listview中的边框在android模拟器中不可见

时间:2017-09-09 19:45:16

标签: android xml

我一直在尝试在我的listview中为我的mainactivity.xml项目设置样式以备注笔记应用。到目前为止,我已成功为每个listview项目实现了背景颜色。 然后我尝试为每个项目显示左侧垂直边框。它在android studio设计视图中可见,但在我在模拟器上运行时不可见。我弄错了吗?我的左侧垂直边框使用View小部件。

MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"

    <ListView
        android:id="@+id/main_listview"
        android:padding="@dimen/activity_listview_margin"
        android:dividerHeight="2dp"
        android:divider="@color/white"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

</RelativeLayout>

listview_component.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_margin="6dp"
    android:background="@color/colorAccent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   <View
// here is where am trying to implement a left vertical border for each list view item
        android:id="@+id/verticallineview"
        android:layout_width="4dp"
        android:layout_height="match_parent"
        android:background="@color/black"
        />

        <TextView
            android:id="@+id/list_note_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:padding="4dp"
            android:textStyle="bold"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/lightBlack" />

    <TextView
        android:id="@+id/list_note_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/colorPrimary"
        android:text=""
       />

    <TextView
        android:id="@+id/list_note_content_preview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text=""
android:textColor="@color/black"
       />
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

尝试在方向水平的组件xml中创建父布局,并在其中创建另一个垂直方向的线性布局以放置三个文本视图

供参考试试这个:

   <?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:background="@color/colorAccent"
    android:orientation="horizontal">

<View
    android:id="@+id/verticallineview"
    android:layout_width="40dp"
    android:layout_height="match_parent"
    android:background="@android:color/black" />


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/list_note_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:text="asdasdaasdasdasdasd"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="@android:color/black"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/list_note_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:text="aasdasdasdasdasdad"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/colorPrimary" />

    <TextView
        android:id="@+id/list_note_content_preview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@android:color/black" />

   </LinearLayout>
</LinearLayout>