0

Android レイアウトに表示するバナーがあります。このバナーには、隣り合わせに表示したい 2 つのアバターがあります。最も重要なのは、y 軸上のこれら 2 つのアバターの中間点が、これらのアバターが上に座るバナー。

これをどのように行いますか?

編集:

つまり、android:layout_below のようなパラメーターを使用する方法を尋ねていますが、イメージビューの上部を指定されたレイアウトの下部に揃える代わりに、中央に揃えます。

ここに画像の説明を入力

4

2 に答える 2

0

それらを線形レイアウトに配置してから、親を埋める幅を指定します。次に、weightプロパティを使用して、幅を均等に分散させることができます。

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


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/clock" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/clock" />

</LinearLayout>
于 2012-08-20T21:54:40.067 に答える
0

残念ながら、中心点を別のエッジに揃えるための直接的なレイアウト パラメータはありません。アバターの高さが固定されている場合は、高さの半分のパディングを追加して、すべてが一列に並ぶようにすることができます。すなわち

<?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="wrap_content">
    <ImageView
        android:id="@+id/banner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="25dp"
        android:src="@drawable/banner" />

    <ImageView
        android:id="@+id/avatar1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignBottom="@id/banner"
        android:src="@drawable/horse" /> 
    <ImageView
        android:id="@+id/avatar2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_alignBottom="@id/banner"
        android:layout_toRightOf="@id/avatar1"
        android:src="@drawable/horse" />
</RelativeLayout>

ただし、これらのアイテムの高さが動的な場合は、実行時ViewGroupにアバターの高さを測定し ( でonMeasure())、パディング (またはその他のオフセット値) を適用できるように、カスタム コンテナーを作成する必要があります。

于 2012-08-20T22:16:20.423 に答える