1

私は2つのビューを切り替えるViewFlipperを持っています.1つのビューはImageViewで、もう1つはTextViewです。
画像とテキストのサイズは、サーバーから取得するものによって異なります。

TextView に関連付けられているテキストが非常に少ない場合でも、ImageView が反転されたときに TextView レイアウトのサイズが変わらないように、TextView の高さ寸法を常に ImageView と同じにしたいと考えています。テキストが多い場合、TextView の高さが ImageView を超える場合は、ellipsize="end" を実行します。

以下は、レイアウトで使用しているコードです。

<ViewFlipper
    android:id="@+id/flipperZoneMediumLeft"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imgZonePic"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/stock_service1"
        android:background="@android:color/black"
        android:scaleType="center" />

    <TextView
        android:id="@+id/txtZoneNameFlipperLeft"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center"
        android:text="This is a description"
        android:background="@android:color/black"
        android:textColor="@android:color/white" />
</ViewFlipper>

この問題には簡単な解決策があるように感じますが、この方法で苦労しています。私の問題を解決するための助けをいただければ幸いです。

4

1 に答える 1

0

と を でラップして、ImageView重みを適用できるようにします。両方の高さを 0dp に設定し、それぞれに layout_weight を 1 に設定します。これにより、常に同じ高さになります。このような:TextViewLinearLayout

<ViewFlipper
    android:id="@+id/flipperZoneMediumLeft"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <ImageView
                android:id="@+id/imgZonePic"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@android:color/black"
                android:scaleType="center"
                android:src="@drawable/stock_service1" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" >

            <TextView
                android:id="@+id/txtZoneNameFlipperLeft"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@android:color/black"
                android:ellipsize="end"
                android:gravity="center"
                android:text="This is a description"
                android:textColor="@android:color/white" />
        </LinearLayout>
    </LinearLayout>

</ViewFlipper>
于 2012-11-07T21:33:36.073 に答える