2015-02-11 78 views
2

我已經在這裏搜索了很多,並且已經實現了通用解決方案。我想是這樣的(紅色邊框列表視圖列項):在ListView的每一行放置一個邊框

enter image description here

我所得到的是這個(紅色邊框僅在頂部可見):

enter image description here

這裏是實現:

ListView.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/gray" 
android:paddingTop="1dp" > 

<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingRight="17dp" 
    android:paddingTop="5dp" 
    android:paddingLeft="17dp"> 

    <ListView 
    android:id="@+id/lv_feeds" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="5.0sp" 
    android:scrollbars="none"> 
    </ListView> 
    </RelativeLayout> 
</android.support.v4.widget.SwipeRefreshLayout> 
</FrameLayout> 

row_listview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/border"> 

..... 
</LinearLayout> 

border.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 

<solid android:color="@color/white" /> 
<stroke android:width="12dp" android:color="@color/app_red"/> 

</shape> 

回答

5

給一些填充左,右線性佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/border" 
android:paddingLeft="5dp" 
android:paddingRight="5dp" 
android:paddingBottom="5dp"> 
    ..... 
    </LinearLayout> 
+0

謝謝你的工作。你可以通過添加'android:paddingBottom =「5dp」'來更新你的答案,它將邊界添加到行的底部。 – stud91 2015-02-11 05:42:40

+0

不適合我 – Amalo 2017-06-20 12:09:56

-1

貫通進入後,你的代碼什麼我得到的是 -

  1. 在您的線性佈局(row_listview.xml)中添加一個12dp的填充以使您的邊框可見。