简体   繁体   中英

Android which layout should i use

I am working in andorid. I want to create a layout like this:-

在此处输入图片说明

When i rotate my android device then it should look like this:-

在此处输入图片说明

There must be some padding between these images. Please suggest me how can i implement this. Which type of layout i should use for this. I am waiting for your suggestions. You may send me some links related to this.

Thank you in advance.

GridLayout or TableLayout

You can find nice tutorials about different layout here

使用GridLayout或TableLayout,但必须编写根据方向显示图像的条件

Use GridLayout . This will work fine for orientation change easily. Here I have posted a sample code .

You need to remove codes for Text.

Download images which used in this example.

This piece of code might help you:

    <TableLayout 
 android:id="@+id/tableLayout1" 
 android:layout_height="wrap_content" 
 android:layout_width="fill_parent" 
 android:layout_marginTop="10dip">

     <TableRow android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dip">
         <TextView android:id="@+id/textView1" 
         android:text="@string/name"
         android:textColor="@color/black" 
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:paddingRight="5dip"
         android:layout_weight=".30"
         android:width="0dip"></TextView>

          <TextView android:id="@+id/name_value" 
         android:text="AAA"
         android:textColor="@color/black" 
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:paddingLeft="5dip" 
         android:singleLine="false"
         android:layout_weight=".70"
         android:width="0dip"></TextView>

     </TableRow>

With this way, you can control any dp of padding or margin wherever you want. on Screen orientation change you can control the layouts. You can change:

    android:layout_weight=".30"

to control the widths of each column.

This is a working code.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM