我如何才能使Listview适合?

时间:2017-08-04 14:22:38

标签: android android-layout listview

我有一个ListView,其中包含ImageView,TextView和Checkbox但是, 当textView很长时,checkBox几乎不可用。我希望ListView适合一行。

如何解决我在图片中提到的问题?

ROW

<LinearLayout

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:padding="0dp"
    android:weightSum="100" >

    <ImageView
        android:id="@+id/newImage"
        android:layout_width="88dp"
        android:layout_height="match_parent"
        android:layout_weight="0.25"
        android:clickable="false"
        android:hapticFeedbackEnabled="false"
        android:saveEnabled="false" />

    <TextView

        android:id="@+id/newTaskTitle"
        android:layout_width="wrap_content"
        android:layout_height="63dp"
        android:layout_alignParentTop="true"
        android:layout_marginStart="11dp"
        android:gravity="center_vertical"
        android:text="Example"
        android:textSize="20sp"
        android:layout_weight="78.57" />

    <CheckBox

        android:id="@+id/checkBox"
        android:layout_width="51dp"
        android:layout_height="match_parent"
        android:layout_weight="18.45"
        android:gravity="left|center"
        android:text="@string/checkBox" />

</LinearLayout>
</RelativeLayout>

LISTVIEW

 <ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="203dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true" />

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:background="@android:color/transparent"
    android:elevation="0dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme" />

LISTVIEW TO FIT PROBLEM (image)

1 个答案:

答案 0 :(得分:1)

您的Imageview宽度已经定义,所以我们应该处理2个视图,其中一个应该总是在右边,中间文本要灵活,所以我们可以给textview赋予权重它会起作用细

你可以试试这个,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <ImageView
            android:id="@+id/newImage"
            android:layout_width="88dp"
            android:layout_height="match_parent"
            android:clickable="false"
            android:hapticFeedbackEnabled="false"
            android:saveEnabled="false"/>

        <TextView

            android:id="@+id/newTaskTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="sdfsdfs"
            android:textSize="20sp"/>

        <CheckBox

            android:id="@+id/checkBox"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="left|center"
            android:text="checkBox"/>

    </LinearLayout>
</RelativeLayout>
相关问题