1

Android のレイアウトに問題があります。作成しようとしているのは、次のようなものです。

<table width="300px">
    <tr>
        <td span="2">test</td>
    </tr>
    <tr>
        <td align="right">image1</td>
        <td align="right">image2</td>
    </tr>
</table>

「image1」と2を一緒にしたいのですが。いずれかの方法、

Androidで使用しているレイアウトは次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TableRow android:layout_gravity="left" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_gravity="left|center_vertical"
            android:layout_span="2"
            android:paddingRight="5dip"
            android:textColor="#ffffffff"
            android:textSize="13dip" />
    </TableRow>

    <TableRow android:layout_gravity="right" >

        <ImageView
            android:layout_width="50px"
            android:layout_height="120px"
            android:layout_column="1"
            android:layout_marginLeft="15dip" />

        <ImageView
            android:layout_width="263px"
            android:layout_height="150px"
            android:layout_column="2"
            android:layout_marginLeft="15dip" />
    </TableRow>

</TableLayout>

また、ImageViews 自体に android:layout_gravity:"right" を配置しようとしましたが、何もしませんでした。

何らかの理由で、この Android レイアウトは常にラベルをインデントし (列にまたがることはありません)、2 行目に右揃えすることはありません。何が間違っているのかわかりません。これは Android 2.1 です。誰でも知っていますか?

4

3 に答える 3

2

わかりました私の答えは次のとおりです。

<?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">

          <TextView
                android:id="@+id/textid"
                android:text="SOME TEXT"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="left"
                android:paddingRight="5dip"
                android:textColor="@color/white"
                android:textSize="13dip" />

            <ImageView
                android:src="@drawable/cloud1"
                android:id="@+id/imageview1"
                android:layout_alignParentRight="true"
                android:layout_below="@id/textid"
                android:layout_width="50dp"
                android:layout_height="120dp"
                android:layout_marginLeft="15dp" />

            <ImageView
                android:src="@drawable/grey_bar"
                android:layout_alignParentRight="true"
                android:layout_below="@id/imageview1"
                android:layout_width="263dp"
                android:layout_height="150dp"
                android:layout_marginLeft="15dp" />

</RelativeLayout>

他にもいくつかのポイントがあります。

  • PX use dp を使用しないでください。これは、密度に依存しないピクセル用です ( What is the difference between "px", "dp", "dip" and "sp" on Android? を参照) 。
  • 最終製品にインラインカラーを使用しないでください。それらを解像度/値/色に入れますが、これを知っていると確信しています
  • 追加した Id の名前を変更し、「android:text」属性と「android:src」属性を削除して、簡単に表示できるようにします。
于 2012-02-06T18:44:02.213 に答える
1

私はこの種のレイアウトでこれを解決することになりました:

<?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="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingRight="5dip"
        android:textColor="#ffffffff"
        android:textSize="13dip" />

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

        <TableRow android:gravity="right" >

            <ImageView
                android:layout_width="50px"
                android:layout_height="120px"
                android:layout_column="1" />

            <ImageView
                android:layout_width="263px"
                android:layout_height="150px"
                android:layout_column="2"
                android:paddingRight="20dip" />
        </TableRow>
    </TableLayout>

</LinearLayout>

また、別の問題は、必要に応じて、コードで幅/高さをピクセル単位で設定していることでした。その場合、列も消去します..したがって、コードは次のようにする必要がありました。

        abc = new TableRow.LayoutParams(myImageWidth,
                mykpiImageHeight);
        abc.column = 2;
于 2012-02-07T18:26:42.620 に答える
0

これは ADT のバグであることが確認されており、ADT 21 で修正されると考えられています。バグ修正を参照してください - 最後に

于 2012-10-17T21:36:02.903 に答える