繁体   English   中英

设置imageview宽度匹配textview宽度

[英]set imageview width match textview width

我想实现这一目标 图片1

但我明白了 图片2

这是我的布局

        <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中的文本是动态的,有什么方法可以缩放imageview宽度来缩放textview宽度

我认为这会起作用,但是我没有尝试。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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