
如何在图像中显示列表项目时如何填充.我想在布局中制作分隔线,如图所示.
这是我的列表片段代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp">
<ListView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/listV_main"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"/>
Run Code Online (Sandbox Code Playgroud)
这是我的List部分代码
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp">
<include
android:id="@+id/list_item_section_text"
layout="@android:layout/preference_category"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的清单项目代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:adjustViewBounds="true"
android:paddingRight="?android:attr/scrollbarSize"
>
<ImageView
android:id="@+id/showlist_item_entry_drawable"
android:layout_width="82dp"
android:adjustViewBounds="true"
android:layout_height="68dp"
android:scaleType="fitXY"
android:paddingLeft="9dp"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1"
>
<TextView android:id="@+id/list_item_entry_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="@+id/list_item_entry_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/list_item_entry_title"
android:layout_alignLeft="@id/list_item_entry_title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我正试图为listview分频器设置一个余量.
分隔线是虚线:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="1dp"
android:dashWidth="1.5dp"
android:width="1dp"
android:color="#FF404040" />
<size android:height="3dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
以及listview我设置分隔符的位置
<ListView
android:id="@+id/lv_news_feed_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:divider="@drawable/ch_dashed_line_divider"
/>
Run Code Online (Sandbox Code Playgroud)
但是我想要左右分隔边距.我也尝试在形状上设置填充,但listview忽略了填充.
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />
Run Code Online (Sandbox Code Playgroud)
是否有可能为listview分频器设置余量- 除了适配器的getView()?
根据这个答案,我能够在垂直RecyclerView的项目之间得到一个分隔符.但是,我也想稍微缩进分隔线.
我能够通过在RecyclerView.ItemDecoration子类中的INDENT值中进行硬编码来实现.
int INDENT = 20;
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
int left = parent.getPaddingLeft() + INDENT;
int right = parent.getWidth() - parent.getPaddingRight() - INDENT;
// ...
divider.setBounds(left, top, right, bottom);
// ...
}
Run Code Online (Sandbox Code Playgroud)
然而,那时我不得不混淆密度无关的像素.