【发布时间】:2014-07-21 13:11:06
【问题描述】:
我有一个奇怪的问题。我的自定义列表视图的分隔线(实际上是在项目布局底部设置为高度为 1dp 的线性布局)在最后一个项目上(在标题之前或在导航抽屉的末尾)绘制两倍的高度。
这就是它的样子
这是我的列表视图项布局 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listItem">
<LinearLayout
android:id="@+id/itemLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:layout_marginTop="0dp"
android:background="@android:color/transparent"
tools:ignore="UselessParent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="55dp"
android:background="@drawable/nav_drawer_bg"
android:id="@+id/itemClickable"
android:paddingLeft="10dp">
<ImageView
android:id="@+id/drawer_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/drawer_itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:layout_gravity="center_vertical"
android:background="@android:color/transparent" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@drawable/border_bottom_header"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"></LinearLayout>
</LinearLayout>
</RelativeLayout>
这是我的列表视图标题 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listItemHeader">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/itemHeader"
android:background="@color/darkgray"
tools:ignore="UselessParent"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/headerText"
android:layout_gravity="center_vertical"
android:textColor="#ffeaeaea"
android:paddingLeft="5dp"
android:paddingTop="2dp"
android:paddingBottom="3dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="@drawable/border_bottom_header"></LinearLayout>
</LinearLayout>
</RelativeLayout>
最后这是我的背景 xml 文件(用于分隔线布局)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#474747"
android:centerColor="#5a5a5a"
android:endColor="#474747"
/>
<corners
android:radius="4dp"
/>
<size
android:height="3dp"/>
</shape>
谁能帮我解决这个问题,我对此感到非常困惑,不知道从哪里开始。感谢您的帮助。
编辑:activity_main.xml 包含列表视图
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#ff1a1a1a"
android:scrollingCache="true"
android:scrollbars="none"/>
</android.support.v4.widget.DrawerLayout>
【问题讨论】:
标签: android layout navigation-drawer