Reputation: 11
I want to add a background image to my linear layout containg 2 text views.. I did that using a frame layout.. But the image is not scaling according to the size of my linear layout.. can anyone help ? The following is my layout file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/button_update_normal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</FrameLayout>
Upvotes: 1
Views: 328
Reputation: 3438
android:background should work but this is another way to fit image acco
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/linearLayout1"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_alignRight="@+id/linearLayout1"
android:layout_alignTop="@+id/linearLayout1"
android:scaleType="fitXY"
android:src="@drawable/button_update_normal" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
Upvotes: 0
Reputation: 414
You can set background of linear layout by
android:background="imagename"
Upvotes: 1
Reputation: 517
I'll suggest you a simpler way. U don't actually need a framelayout to do wat you are trying to do. U can set your background image in your linearlayout itself. See the following code.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background= "@drawable/yourBackgroundImage >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
Upvotes: 0
Reputation: 3285
In your ImageView, change android:layout_height="wrap_content"
to android:layout_height="fill_parent"
Upvotes: 0
Reputation: 2170
You can use android:background attribute of your LinearLayoutr. Set image as linear layout background.
Upvotes: 0