【问题标题】:Textview width is not the fit the width of the parentTextview 宽度不适合父级的宽度
【发布时间】:2016-04-18 15:29:28
【问题描述】:

我无法使 Textview 和线性布局的宽度相等。虽然在 Textview 中设置了宽度 match_parent 但它不适合父宽度。

我看到这个帖子: Android textView width not increasing

Android TextView does not expand to match parent

TextView width match drawableTop width

How to adjust text font size to fit textview

How to adjust text font size to fit textview

但是我的问题没有解决

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right|center_vertical"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:src="@drawable/defaultpicpic" />

    <TextView
        android:id="@+id/title"
        style="@style/textViewItemStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:paddingTop="10dp" />


</LinearLayout>

【问题讨论】:

    标签: width android-linearlayout textview android


    【解决方案1】:

    我解决了我的问题,将视图包装在 LinearLayout 中,然后在下方加上一个小的 View

    目前尚不清楚为什么会这样。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="right|center_vertical"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="right|center_vertical"
            android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:src="@drawable/thumb" />
    
            <TextView
                android:id="@+id/title"
                style="@style/textViewItemStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp" />
    
        </LinearLayout>
    
        <View
            android:layout_width="match_parent"
            android:layout_height="2px" />
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 2020-05-09
      • 2017-10-01
      • 2018-11-05
      相关资源
      最近更新 更多