设置imageview宽度匹配textview宽度

时间:2015-11-10 16:50:28

标签: android textview imageview

我想实现这一目标 detach

但我得到了这个 image 1

这是我的布局

        <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/black">
        <ImageView
            android:id="@+id/imf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/frame001"
            />

        <TextView
            android:id="@+id/firetext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="170dp"
            android:text="Android"
            android:textStyle="bold"
            android:textColor="@android:color/white" />


    </RelativeLayout>

有没有办法缩放图像视图宽度以缩放文本视图宽度,因为textview中的文本是动态的

2 个答案:

答案 0 :(得分:0)

我认为这会奏效,但我没试过。

<LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/black"
            android:orientation="vertical">
            <ImageView
                android:id="@+id/imf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/frame001"
                />

            <TextView
                android:id="@+id/firetext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="170dp"
                android:text="Android"
                android:textStyle="bold"
                android:textColor="@android:color/white" />


        </LinearLayout>

答案 1 :(得分:0)

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/black">
    <ImageView
        android:id="@+id/imf"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/frame001"
        android:layout_alignLeft="@+id/firetext"
        android:layout_alignRight="@+id/firetext" />

    <TextView
        android:id="@+id/firetext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="170dp"
        android:text="Android"
        android:textStyle="bold"
        android:textColor="@android:color/white" />