我想改变ListView分隔线的颜色.任何帮助,将不胜感激.
我有一个渐变的形状,我用它作为ListView物品之间的分隔物.我把它定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我想在渐变的两侧添加6个像素的填充,这样它就不会从屏幕的边缘延伸到边缘.
但是,无论身在何处,我把一个android:left="6px"和android:right="6px",它似乎并没有生效.我可以把它放在<shape>元素,<gradient>元素或者单独的<padding>子元素中,<shape>它不会改变任何东西.
如何在列表分隔符的左侧和右侧添加填充?
我有一个带BaseAdapter的ListView.在XML中,我将项目分隔符指定为红色,高度为10dip.
<ListView android:layout_width="fill_parent"
android:layout_height="0px"
android:id="@+id/lv"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:divider="#FF0000"
android:dividerHeight="10dip"
android:fadingEdge="none">
</ListView>
Run Code Online (Sandbox Code Playgroud)
但是,当应用程序运行时,我没有看到项目之间的红色分隔符.有人可以告诉我为什么吗?谢谢.
编辑:在我的适配器代码中,我有以下代码:
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
return false;
}
Run Code Online (Sandbox Code Playgroud)
因为我想控制每个项目的onClick行为.我不知道上面的代码是否会使分隔符消失.
我有一个简单的列表视图,我已经为分隔符定义了一个自定义drawable.我已将分隔符高度定义为1dp.列表视图位于片段内.
<shape
android:shape="line" >
<stroke
android:color="@color/custom_color" />
<gradient android:height="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
它适用于除L以外的所有Android版本.
我缺少什么?
android android-layout android-listview android-5.0-lollipop
我试图从style.xml为所有listViews应用默认样式
请注意我在某些地方使用嵌套的listViews.
在style.xml中
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:windowContentOverlay">@null</item>
<item name="android:listViewStyle">@style/awesomeListViewStyle</item>
</style>
<style name="awesomeListViewStyle" parent="@android:style/Widget.ListView">
<item name="android:fadingEdge">none</item>
<item name="android:background">@color/orange</item>
<item name="android:divider">#EEEEEE</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这没有效果.在Manifest Theme.MyTheme作为我的默认主题.请指教 :)
我正在使用Android Listview,并且我想在listview项目的两侧使用1px分隔符意味着在两种不同颜色的顶部和底部.但问题是我没有登录以显示底部的分隔符.我尝试了,android:layout_below但显示无效.
这是Listview代码
<ListView
android:id="@+id/myphnview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@drawable/dividerheight"
android:background="#E9EAEC"
android:clickable="true"
android:divider="@drawable/dividerheight" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
这是我用于顶部边框的xml文件.dividerheight.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="line" >
<stroke android:color="#c6c7c9" />
<size android:height="1px" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
这是我的行的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rowlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E9EAEC"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<TextView
android:id="@+id/file_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_margin="5dp"
android:text="Hello Android "
android:textColor="@android:color/black"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp" …Run Code Online (Sandbox Code Playgroud) 我正在尝试将默认的ListView列表分隔符设置为在两边都有空白边距.我已经尝试设置整个ListView的边距,但是没有创建所需的结果.
是)我有的:

我想要做什么(注意分隔线两侧的边距):

这样做的最佳方式是什么?提前致谢!