manuelBetancurt
manuelBetancurt

Reputation: 16128

android layout image fill width

I need to strech a background image for a layout in my app,

please note, the yellow background in my layout is not streched

enter image description here

how to accomplish this [yellow bar image filling parent]?

also please note that the blue layout is not the whole width of the screen, how to?

code:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="8dp"
         android:paddingRight="8dp"
         android:id="@+id/myfragment">

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="50dp"
         android:layout_weight="1" 
          android:background="#0000FF">

         <ImageView
             android:id="@+id/imageView1"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:src="@drawable/titlebar" />

     </LinearLayout>

     <ListView android:id="@id/android:list"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>




 </LinearLayout>

Thanks a lot!

Upvotes: 0

Views: 1413

Answers (1)

Shubhayu
Shubhayu

Reputation: 13552

This is the reason why your linearlayout (blue) is not fitting the whole screenwidth

android:paddingLeft="8dp" 
android:paddingRight="8dp"

You need to change this. Put a margin (left and right) for the inner layout instead.

Instead of the image view you could set the background of the 2nd linearlyout directly

android:background="@+id/imageView1"

Incase you want to use the image view instead

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="fill_parent"
         android:layout_height="50dp"
         android:scaleType="fitXY"
         android:src="@drawable/titlebar" />

Upvotes: 2

Related Questions