как поставить значок справа в макете таблицы Android? - PullRequest
0 голосов
/ 12 февраля 2012

Я использую tablelayout вместо пользовательской строки заголовка

Теперь мой макет, такой как xml, показан ниже, и я хочу, чтобы значок 2 и текст выровнялись вправо, но когда я использую android:layout_gravity="right"кажется, не работает, так как я могу это сделать?

Это мой макет XML:

  < ? xml version="1.0" encoding="utf-8"?>
  < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >    
        <TableLayout
            android:id="@+id/tableLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:background="#4494D1" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right" >

                <LinearLayout
                    android:id="@+id/linearLayout3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <TextView

                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:text="简易尺子" 
                        android:textColor="#fff"
                        android:textSize="25dp"
                        android:layout_marginTop="5dp"
                         android:layout_marginLeft="15dp"
                        />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/linearLayout1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" 

                    >

                    <ImageButton
                        android:id="@+id/imageButton1"
                        android:layout_width="28dp"
                        android:layout_height="28dp"
                        android:background="@drawable/android2"
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="15dp"
                        android:layout_marginTop="5dp"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="关于"
                        android:textColor="#fff" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/linearLayout2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right"
                    android:orientation="vertical" >

                    <ImageButton
                        android:id="@+id/imageButton2"
                        android:layout_width="28dp"
                        android:layout_height="28dp"
                        android:background="@drawable/programs" 
                        android:layout_marginLeft="15dp"
                        android:layout_marginRight="15dp"
                        android:layout_marginTop="5dp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="帮助"
                        android:textColor="#fff" />

                </LinearLayout>
            </TableRow>
        </TableLayout>

    <SurfaceView
        android:layout_width="match_parent"
        android:id="@+id/surfaceView1"
        android:layout_height="match_parent">
    </SurfaceView>
</LinearLayout>

Ответы [ 2 ]

0 голосов
/ 04 июля 2012
try this


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


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

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dip" >

            <TextView
                android:id="@+id/textView2"
                android:text="简易尺子"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <RelativeLayout
                android:id="@+id/relativeLayout2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="right" >

                <ImageButton
                    android:id="@+id/imageButton1"
                    android:layout_width="28dp"
                    android:layout_height="28dp"
                    android:layout_marginRight="10dp"
                    android:layout_toLeftOf="@+id/imageButton2" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/imageButton1"
                    android:layout_marginRight="10dp"
                    android:layout_toLeftOf="@+id/text2"
                    android:text="关于"
                    android:textColor="#fff" />

                <ImageButton
                    android:id="@+id/imageButton2"
                    android:layout_width="28dp"
                    android:layout_height="28dp"
                    android:layout_alignParentRight="true" />

                <TextView
                    android:id="@+id/text2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/imageButton2"
                    android:text="帮助"
                    android:textColor="#fff" />
            </RelativeLayout>
        </TableRow>
    </TableLayout>

    <SurfaceView
        android:id="@+id/surfaceView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/tableLayout1" >
    </SurfaceView>

</RelativeLayout>
0 голосов
/ 12 февраля 2012

Гравитация макета, которую вы устанавливаете, не влияет на позиционирование TextView и ImageView в TableRow, скорее она будет помещать их в оболочку LinearLayout, что не совсем то, что вам нужно.Я предлагаю вам определить следующий атрибут для вашего TableLayout:

<TableLayout
    android:layout_width="fill_parent"
    android:layout_width="wrap_content"
    android:stretchColumns="0,1">

. Это расширит первые два столбца необработанного текста и, таким образом, уменьшит самый правый столбец вправо.

ПРИМЕЧАНИЕ (ВАЖНО) В настоящее время у вас не определен правильный макет: у вас есть TableRow в LinearLayout - это недопустимо - вы должны поместить строку в TableLayout, как тот, который я определил.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...