Can I use background image but contain it within a nested view?

429 Views Asked by At

I'm trying to create a screen with one button on top (full width), a background image in the middle with scaletype fitXY to stretch to fit the center area, and 4 full width buttons on the bottom. I've almost got this but the background image fills the FULL screen background (covering up part of the image), not just the area withing the nested ListView. Is it possible to contain a background image to a specific portion of the screen (inside the nested child view only)?

UPDATE: The image may be just getting cropped so it doesn't look like it's staying inside the linearlayout. Is there a way to use scaleType="fitXY" with a background image? Put it inside a drawable.xml file perhaps?

UPDATE2: pasted actual xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"  
android:orientation="vertical" >


<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/pictureplaybk3"  >

<Button
  android:id="@+id/Signup_login_button"
  android:layout_width="match_parent"
  android:textColor="#ffffff"
  android:background="#1a2a50"
  android:layout_height="36sp"
  android:layout_gravity="top"
  android:onClick="onLoginSignupButtonClick"
  android:text="@string/login" />

<TextView
    android:id="@+id/home_instructions"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:text="@string/home_instructions"
    android:textColor="#ffffff"
    android:background="#1a2a50"
    android:layout_gravity="top"
    android:textSize="20sp"
    android:textStyle="bold"
    android:visibility="gone" />

<ScrollView
    android:id="@+id/main_scroll"
    android:layout_width="fill_parent"
    android:layout_gravity="bottom"
    android:layout_marginTop="10dp"
    android:fadeScrollbars="true"
    android:scrollbarStyle="insideInset"
    android:layout_height="wrap_content">
    <LinearLayout 
        android:id="@+id/main_scroll_linearlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="top"
        android:scrollbars="vertical" >

    </LinearLayout>
</ScrollView>

</LinearLayout>

 <LinearLayout
     android:id="@+id/bottom_buttons1" 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom"
     android:orientation="vertical"
     android:layout_alignParentBottom="true" >

    <Button
         android:id="@+id/waiting_comments_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onGetCommentsButtonClick"
         android:text="@string/get_comments"
         android:visibility="invisible" />

     <Button
         android:id="@+id/send_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onSendButtonClick"
         android:text="@string/send_picture"
         android:visibility="invisible" />

     <Button
         android:id="@+id/guess_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onGuessButtonClick"
         android:text="@string/guess_picture"
         android:visibility="invisible" />

     <Button
         android:id="@+id/invite_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onInviteFriendButtonClick"
         android:text="@string/invite_friend"
         android:visibility="invisible" />

 </LinearLayout>

</RelativeLayout>
1

There are 1 best solutions below

3
On

Yes. Wrap the scrollview or listview in a linearlayout and set the background image of that linearlayout.

<LinearLayout ...>

  <Button ... />
<LinearLayout 
  android:background="@drawable/imagename"
  ... >
  <ScrollView ... > (holds more dynamic buttons)
</LinearLayout>

<LinearyLaout ...>
  <Button .../>
  <Button .../>
  <Button .../>
  <Button .../>
 </LinearLayout

</LinearLayout>

Edit:

Try something like this:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"  
android:orientation="vertical" >
<Button
  android:id="@+id/Signup_login_button"
  android:layout_width="match_parent"
  android:textColor="#ffffff"
  android:background="#1a2a50"
  android:layout_height="36sp"
  android:layout_gravity="top"
  android:onClick="onLoginSignupButtonClick"
  android:text="login" />

<LinearLayout
     android:id="@+id/bottom_buttons1" 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom"
     android:orientation="vertical"
     android:layout_alignParentBottom="true" >

    <Button
         android:id="@+id/waiting_comments_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onGetCommentsButtonClick"
         android:text="get_comments"
         android:visibility="invisible" />

     <Button
         android:id="@+id/send_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onSendButtonClick"
         android:text="send_picture"
         android:visibility="invisible" />

     <Button
         android:id="@+id/guess_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onGuessButtonClick"
         android:text="guess_picture"
         android:visibility="invisible" />

     <Button
         android:id="@+id/invite_button"
         android:layout_width="match_parent"
         android:textColor="#ffffff"
         android:background="#1a2a50"
         android:layout_height="36sp"
         android:layout_gravity="center_horizontal"
         android:onClick="onInviteFriendButtonClick"
         android:text="invite_friend"
         android:visibility="invisible" />

 </LinearLayout>

<LinearLayout
    android:layout_below="@id/Signup_login_button"
    android:layout_above="@id/bottom_buttons1"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/pictureplaybk3"  >



<TextView
    android:id="@+id/home_instructions"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="top"
    android:text="home instructions"
    android:textColor="#ffffff"
    android:background="#1a2a50"
    android:layout_gravity="top"
    android:textSize="20sp"
    android:textStyle="bold"
    android:visibility="gone" />

<ScrollView
    android:id="@+id/main_scroll"
    android:layout_width="fill_parent"
    android:layout_gravity="bottom"
    android:layout_marginTop="10dp"
    android:fadeScrollbars="true"
    android:scrollbarStyle="insideInset"
    android:layout_height="wrap_content">
    <LinearLayout 
        android:id="@+id/main_scroll_linearlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="top"
        android:scrollbars="vertical" >

    </LinearLayout>
</ScrollView>

</LinearLayout>

</RelativeLayout>