android – 将ImageView缩放为XML格式的TextView

前端之家收集整理的这篇文章主要介绍了android – 将ImageView缩放为XML格式的TextView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个水平线性布局的TextView和 ImageView.是否可以缩放ImageView以使其相对于布局文件中TextView的大小?

基本上我想要的东西: –

而不是像这样的东西

布局文件将是

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView />
    <TextView />
</LinearLayout>

解决方法

是的,您可以在相对于TextView的高度缩小ImageView.要匹配TextView的高度,请将match_parent设置为ImageView的android:layout_height,这将有助于ImageView获取TextView的高度.尝试如下……
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textSize="30sp" />
</LinearLayout>

您也可以通过以下方式获得相同的结果……

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_launcher"
    android:text="TextView"
    android:gravity="center_vertical"
    android:textSize="30sp" />
原文链接:https://www.f2er.com/android/309644.html

猜你在找的Android相关文章