简体   繁体   中英

set imageview width match textview width

i want to achieve this 图片1

but i got this 图片2

here is my layout

        <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>

is there any way to scale the imageview width to scale the textview width considering that the text in the textview is dynamic

I think this will work, but I did not try it.

<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>
<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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM