3

次の内容の XML を作成する必要があります

* 2 つの TextViews の右側にある 1 つの ImageView。垂直方向に中央揃え、30x30 ピクセル。

主な制限の 1 つは、PopupWindow に膨張させたときに画面全体を使用できないことです。つまり、多くの場所で属性 fill_parent を使用できません。

私は多くの異なるレイアウトを試しましたが、テキストが長い場合、ImageView は TextViews によって押しのけられ続けます。テキストが「半分の長さ」の場合、画像は小さくなりますが、それでも表示されます。常に 30x30 ピクセルにしたいので、テキストを折り返して代わりに別の行を使用できます。

width と minWidth の値を指定しようとしました。ImageView の layout_weight="1" も試しました。また、ImageView を LinearLayout にラップして、layout_weight="1" パラメータを指定してみました。何も機能しません。

機能していないものの例を次に示します。

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

    <LinearLayout android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:orientation="vertical">

       <TextView android:id="@+id/popupTitle" android:layout_width="wrap_content"
      android:layout_height="wrap_content"/>

       <TextView android:id="@+id/popupContent"
      android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    </LinearLayout>

    <ImageView android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:src="@drawable/img_30x30_px" />
 </LinearLayout>
4

2 に答える 2

3

同様の問題が発生しましたが、TableViewレイアウトが機能することがわかりました。しばらく時間がかかりましたが、ストレッチ列とストリンク列のプロパティを試して、列がコンテンツに一致するように拡張する方法の動作を変更できます。

テキストのlinearLayoutをfill_parentに設定できるはずであることに注意してください(列スペースを埋めるため)。

TableRowの仕組みについてはこちらをご覧くださいhttp://developer.android.com/resources/tutorials/views/hello-tablelayout.html

<TableRow>
    <!-- Column 1 -->
    <LinearLayout android:layout_width="fill_parent"
   android:layout_height="wrap_content" android:orientation="vertical">

            <TextView
                android:layout_column="1"
                android:text="Open..."
                android:padding="3dip" />
            <TextView
                android:text="Ctrl-O"
                android:gravity="right"
                android:padding="3dip" />
    </LinearLayout>
    <!-- Column 2 -->
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/img_30x30_px" />
</TableRow>

(私はAndroidを搭載したマシンを使用していないため、上記のコードをテストできませんでした)。

于 2010-11-05T15:37:13.983 に答える
0

エミール本当にありがとう!できます!あなたは私の週末を作りました!:)

私はすぐにそれを試してみる必要がありました (金曜日の夜ですが)、私の xml は次のようになります。

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

<TableRow>
<!-- Column 1 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">

  <TextView android:id="@+id/popupTitle"
  android:layout_width="wrap_content" android:layout_height="wrap_content"/>

  <TextView android:id="@+id/popupContent"
  android:layout_width="wrap_content" android:layout_height="wrap_content" />
  </LinearLayout>

  <!-- Column 2 -->
  <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:layout_gravity="center_vertical" android:src="@drawable/img_30x30_px" />

</TableRow>
</TableLayout>
于 2010-11-05T18:56:17.937 に答える