【问题标题】:Add a border at the end of a listview in a two listview fragment在两个列表视图片段中的列表视图末尾添加边框
【发布时间】:2016-02-13 20:22:10
【问题描述】:

正如标题所说,我有一个带有两个列表视图的片段,我想在第二个列表视图的末尾添加一个边框。我知道这通常是在 xml 写作中实现的:

android:paddingBottom="50dp"
android:clipToPadding="false"

当我只使用一个 listView 时,它可以完美运行,但不能使用两个,我不知道为什么。 我尝试在我的 baseAdapter 的 getView 中添加一个白色布局,但问题是我想管理我使用的长点击:

listViewSin.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
listViewSin.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {...});

并且在这种方法中,我无法知道在创建菜单之前单击的视图类型,因此我不想添加新视图。

布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dip" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="@string/sin"
            android:textColor="@color/black"
            android:textSize="15sp"
            android:id="@+id/android"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000000"
            />


        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:background="#FFFFFF"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:gravity="center_vertical"
            android:text="@string/hechos"
            android:textColor="#A2A2A2"
            android:id="@+id/ios"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#A2A2A2"
            />

        <ListView
            android:id="@+id/listView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:background="#A2A2A2"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:paddingBottom="80dp"
            android:clipToPadding="false"
            />

    </LinearLayout>

</ScrollView>
<android.support.design.widget.FloatingActionButton
    android:id="@+id/tareas_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:src="@drawable/add"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="10dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="10dp" />

【问题讨论】:

  • @HrundiV.Bakshi 添加了
  • 拜托!嵌套的可滚​​动视图是一种糟糕的设计!而且您不需要 RelativeLayout 或 LinearLayout - 取决于您选择哪一个(我会选择 RelativeLayout)。
  • @HrundiV.Bakshi 那我该怎么办? (我是 android 的新手)
  • 首先了解视图在RelativeLayout 中如何相互关联。然后了解边距。就是这样。

标签: android listview android-fragments


【解决方案1】:

以类似于此处解释的方式定义可绘制形状:

Android border bottom for custom view not working

将矩形的颜色设置为您的ListView's 背景颜色,并将笔划的颜色设置为您想要的底部边框颜色。然后在 xml 中,在您的 ListView 元素背景属性中,使用 @drawable/... 引用形状。

【讨论】:

    猜你喜欢
    • 2021-06-05
    • 2017-01-28
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多