ListView在较小的手机中出现裁剪

时间:2017-11-03 09:55:26

标签: android android-layout listview

我的listView布局有问题,在大手机中效果很好但是在最小的时候,tittle似乎从左边裁剪掉,在某些情况下与imageview重叠。

这是我的task_layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.usuario.tasker.activities.TasksActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_tasks"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:text="TextView"
            android:textColor="@color/white_title"
            android:textSize="@dimen/titles" />


        <Button
            android:id="@+id/btn_add_task"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:background="@color/colorPrimary"
            android:text="+"
            android:textColor="@color/white_title"
            android:textSize="@dimen/titles" />
    </RelativeLayout>

    <ListView
        android:id="@+id/lv_tasks"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ListView>

</LinearLayout>

我的item_list_layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout2"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:layout_editor_absoluteY="25dp">


    <TextView
        android:id="@+id/item_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="Título de la tarea"
        android:textColor="@color/white_title"
        android:textSize="@dimen/sub_title"
        app:layout_constraintEnd_toStartOf="@+id/item_edit"
        app:layout_constraintHorizontal_bias="0.481"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/item_delete"
        android:layout_width="37dp"
        android:layout_height="@dimen/iconSize"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toStartOf="@+id/item_done"
        app:layout_constraintTop_toTopOf="parent"
        android:tint="@color/white_title"
        app:srcCompat="@drawable/ic_delete_black_24dp" />

    <ImageView
        android:id="@+id/item_edit"
        android:layout_width="@dimen/iconSize"
        android:layout_height="@dimen/iconSize"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toStartOf="@+id/item_delete"
        app:layout_constraintTop_toTopOf="parent"
        android:tint="@color/white_title"
        app:srcCompat="@drawable/ic_edit_black_24dp" />

    <CheckBox
        android:id="@+id/item_done"
        android:layout_width="@dimen/iconSize"
        android:layout_height="@dimen/iconSize"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:theme="@style/WhiteCheck"

         />


    <View
        android:id="@+id/view4"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginTop="16dp"
        android:background="#000"
        app:layout_constraintTop_toBottomOf="@+id/item_title"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteX="0dp" />

    <TextView
        android:id="@+id/item_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:text="Hay que hacer un backup del servidor"
        android:textColor="@color/white_title"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view4" />

    <TextView
        android:id="@+id/item_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="31/10/2017"
        android:textColor="@color/white_title"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.843"
        app:layout_constraintStart_toEndOf="@+id/item_description"
        app:layout_constraintTop_toBottomOf="@+id/item_description" />
</android.support.constraint.ConstraintLayout>

我能做些什么让它适用于每部手机?我认为这可能是item_list_layout的错误,但我不确定如何让它更好。

1 个答案:

答案 0 :(得分:2)

尝试此布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.usuario.tasker.activities.TasksActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_tasks"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_weight="1"
            android:layout_gravity="right"
            android:textColor="@color/white_title"
            android:textSize="@dimen/titles" />


        <Button
            android:id="@+id/btn_add_task"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:gravity="right"
            android:layout_weight="1"
            android:background="@color/colorPrimary"
            android:text="+"
            android:textColor="@color/white_title"
            android:textSize="@dimen/titles" />
    </LinearLayout>

    <ListView
        android:id="@+id/lv_tasks"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ListView>

</LinearLayout>`