Разработка макета в Android с помощью TableLayout и Gallery - PullRequest
0 голосов
/ 15 февраля 2011

У меня есть два ImageView s, один TextView и один Gallery в моем приложении, и я хочу, чтобы мой макет был показан ниже.как показано выше, за исключением того, что при небольшой длине текста ImageView в правом конце экрана продолжает двигаться.Я хочу, чтобы значения ImageView в левом и правом концах экрана фиксировались независимо от размера текста.

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

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content">

         <TableRow>
              <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/imageL"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"  
                   android:layout_weight="1"
                   android:minHeight="30px"
                   android:minWidth="30px" />

              <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/title"
                   android:paddingLeft="10px"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content" 
                   android:layout_weight="3"
                   android:layout_gravity="center"
                   android:minHeight="30px"
                   android:minWidth="30px" />

               <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
                   android:id="@+id/imageR"
                   android:paddingLeft="10px"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"
                   android:layout_weight="1"
                   android:minHeight="30px"
                   android:minWidth="30px" />
          </TableRow> 
    </TableLayout>

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/gallery"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" />
</LinearLayout>

Ответы [ 3 ]

0 голосов
/ 15 февраля 2011

Используйте одинаковый вес для всех трех предметов, проблема должна быть решена.

android:layout_weight="1"

все 3 будут занимать равные области.

0 голосов
/ 15 февраля 2011

Добавьте это к вашему TableLayout-тегу:

android:shrinkcolumns="0,2" android:stretchColumns="1"

Кроме того, вы можете вместо этого изменить layout_width на fill_parent, так как это позволит растянуть средний столбец.

0 голосов
/ 15 февраля 2011

Как-то так.Если вы хотите сделать статическую ширину и высоту для IMG, вы можете установить его в Android: layout_width и Android: layout_height

<?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"
>
    <ImageView 
    android:id="@+id/firstImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/icon"
    />
    <TextView 
    android:id="@+id/someText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/secondImage"
    android:layout_toRightOf="@+id/firstImage"
    android:text="some mega text."
    android:gravity="center_horizontal"
    />
    <ImageView 
    android:id="@+id/secondImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/icon"
    />

</RelativeLayout>
...