How do I minimize spacing on left and right side of image view? My xml file shows much space on left and right side of image. My screen looks like this:
and I want to make it like this:
How do I reduce spacing on left and right side of images?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="70dp"
android:layout_height="80dp"
android:contentDescription="@null"
android:background="@drawable/imagebgborder"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/img2"
android:layout_width="70dp"
android:layout_height="80dp"
android:contentDescription="@null"
android:background="@drawable/imagebgborder"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/img3"
android:layout_width="70dp"
android:layout_height="80dp"
android:contentDescription="@null"
android:background="@drawable/imagebgborder"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:contentDescription="@null"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
I've done something like this and had success using a TableLayout instead for the main content (your 3 items). http://developer.android.com/reference/android/widget/TableLayout.html
Updated code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" >
<!-- NEW LINEAR LAYOUT -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<!-- Your individual items go here -->
<TableLayout
android:id="@+id/tableLayoutPlacard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_vertical" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="70dp"
android:layout_height="80dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:gravity="center"
android:text="ITEM 1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="70dp"
android:layout_height="80dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:gravity="center"
android:text="ITEM 2"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/img1"
android:layout_width="70dp"
android:layout_height="80dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:background="#FFFFFF"
android:contentDescription="@null"
android:gravity="center"
android:text="ITEM 3"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.