0

画像とテキストのレイアウトを機能させるために助けが必要です。

TextViewで使用するのと同じ高さに画像を拡大縮小したい。画像もテキストに残したいです。たとえば、#私の画像です

# "My Text"

また

## "My long text
## is this here"

画像のウィットは、画像がアスペクトを維持するようになります。

私のコードはこれで、基本的なレイアウトは機能しますが、画像が大きくなります。

        <LinearLayout 
            android:id="@+id/packet_list_view_layout_subvehicle" android:layout_width="fill_parent"
            android:layout_weight="1" android:orientation="horizontal"
            android:gravity="left" android:layout_height="wrap_content">
            <ImageView 
                android:id="@+id/packet_list_view_layout_subvehicle_image"
                android:src="@drawable/packet"
                android:scaleType="fitCenter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/packet_list_view_layout_subvehicle_text"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="==================="
                />

編集1

私に同じ結果を与える別の試み。

        <LinearLayout
            android:id="@+id/packet_list_view_layout_subvehicle"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:gravity="left"
            android:layout_height="wrap_content"
        >
            <ImageView
                android:id="@+id/packet_list_view_layout_subvehicle_image"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:scaleType="fitCenter"
                android:src="@drawable/packet" />
            <TextView
                android:id="@+id/packet_list_view_layout_subvehicle_text"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="TV's (20) to London"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>

編集2

私は今、半分機能するコードを見つけました。ここでの問題は、画像の幅が元の幅であり、新しいスケールの幅ではないことです。

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/packet_list_view_layout_subvehicle"
        >
            <ImageView
                android:id="@+id/packet_list_view_layout_subvehicle_imageAA"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:src="@drawable/packet"
                />

            <TextView
                android:id="@+id/packet_list_view_layout_subvehicle_text"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center|left"
                android:text="TV's (20) to London"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>
4

1 に答える 1

0

私はついにうまくいく方法を見つけました。あまり良くはありませんが、私のために働きます。

私のコードは今です

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/packet_list_view_layout_subvehicle"
        >
            <mypacket.MyImageView
                android:id="@+id/packet_list_view_layout_subvehicle_imageAA"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:src="@drawable/packet"
                />

            <TextView
                android:id="@+id/packet_list_view_layout_subvehicle_text"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center|left"
                android:text="TV's (20) to London"
                android:textAppearance="?android:attr/textAppearanceSmall" />
        </LinearLayout>

そして、mypacket.MyImageViewこれがこのコードです。

public class MyImageView extends ImageView {

    public MyImageView(Context context) {
        super(context);
    }
    public MyImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public MyImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(heightMeasureSpec, heightMeasureSpec);
    }
}

編集:実際、私はこれを使用していません。システムがサイズを計算する方法にいくつかのエラーがあります。これにより、画像が必要以上に大きくなり、テキストが2行にワープします。最後に、通常のImageViewを使用して、fixhegthとwithdを設定します。

于 2012-10-22T16:09:11.033 に答える