2

プロジェクトで新しいアクティビティを作成する必要があり、写真を表示したいと考えています。作りたいレイアウトはこんな感じです。

ここに画像の説明を入力

すべての高さに「wrap_content」プロパティが必要です。

どのレイアウトを使用する必要がありますか?

4

4 に答える 4

0

TableLayoutまたはGridViewの使用を検討し、子で属性layout_weightを使用します。

最初の子 (66%) のレイアウト ウェイトは 2、2 番目 (33%) のレイアウト ウェイトは 1 です。

次に、最初の子は幅の 2/3 (66%) を占め、2 番目の子は 1/3、つまり 33% を占めます。

そして、layout_span属性を使用して、2 つの列の最後のビューを展開します。

例えば ​​:

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

    <TableRow>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
    </TableRow>

    <TableRow>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="2" />
    </TableRow>
</TableLayout>

layout_weight の説明については、その質問も参照してください。

于 2013-06-14T08:31:01.077 に答える
0

なぜ wrap_content の使用を主張するのですか? ボックスの幅が「固定」されています (66% と 33%)。これを達成するために sp/dp 単位を使用できると確信しています。もちろん、微調整を加えて。

このトピックに関する詳細について は、 http://developer.android.com/guide/practices/screens_support.html に アクセスしてください。Android での "px"、"dp"、"dip"、"sp" の違いは何ですか?

于 2013-06-14T08:36:36.600 に答える