2015-01-13 5 views
0

Android보기를 사용하여 목록보기가있는 응용 프로그램을 만들었습니다. 탐색 창을 사용하기 위해 프로젝트를 선택한 후에 내 활동에 listview 컨트롤을 추가했습니다.Android : Youtube 응용 프로그램에서 멋진 목록보기를 만드는 방법

나는 인터넷을 살펴본 결과 listview 행을 사용자 정의하는 것에 대한 예제가 필요하지 않았기 때문에 항목 사이에 둥근 모서리와 음영 및 더 큰 공간이있는 Youtube 응용 프로그램에서 항목/행을 만들어야했습니다.

사용자 정의 행이있는 목록보기 컨트롤입니까, 복합 컨트롤 (항목/행) 및 세로 스크롤 막대가있는 활동입니까?

[스크린 샷 유튜브에서 응용 프로그램]

enter image description here

편집 1 :

여기

내 코드가 @Saeed 접근 방식을 사용하고,하지만 약간의 문제에 직면하고있어, Shape Stroke를 사용하여 왼쪽/오른쪽/위쪽/아래쪽 여백을 지정하면 두 목록 항목 사이에 위쪽/아래쪽 여백의 두 배 크기가 생깁니다. 개별적으로 각 여백을 어떻게 설정할 수 있습니까?

enter image description here

list.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="200dp" 
android:background="@drawable/background_with_shadow"> 

<!-- icon --> 
<ImageView 
    android:id="@+id/item_icon" 
    android:layout_width="32dp" 
    android:layout_height="32dp" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:src="@drawable/abc_ic_search_api_mtrl_alpha" 
    /> 

<!-- title --> 
<TextView 
    android:id="@+id/item_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/item_icon" 
    android:layout_alignBaseline="@+id/item_counter" 
    android:textSize="18dp" /> 

<!-- counter --> 
<TextView 
    android:id="@+id/item_counter" 
    android:layout_width="32dp" 
    android:layout_height="32dp" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    android:background="@drawable/rectangle" 
    android:gravity="center" 
    android:textColor="#FFFFFF" 
    android:textSize="12sp" 
    android:textStyle="bold" /> 

background_with_shadow.xml

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

    <item > 
     <shape 
      android:shape="rectangle"> 
      <solid android:color="#C8C8C8" /> 
      <corners android:radius="2dp"/> 
      <!-- Not needed anymore after using padding and divider in ListView--> 
      <!-- <stroke android:width="20dp"/> --> 
     </shape> 
    </item> 

    <item android:right="0.5dp" android:left="0.5dp" android:top="0.5dp" android:bottom="1.5dp"> 
     <shape 
      android:shape="rectangle"> 
      <solid android:color="@android:color/white"/> 
      <corners android:radius="2dp"/> 
      <!-- Not needed anymore after using padding and divider in ListView--> 
      <!-- <stroke android:width="20dp"/> --> 
      <padding android:left="7dp" android:right="7dp" 
        android:top="7dp" android:bottom="7dp" /> 
     </shape> 
    </item> 
</layer-list> 

activity_main.xml

<ListView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/listView" 
     android:layout_gravity="center_horizontal|top" 
     android:dividerHeight="10dp" 
     android:divider="@android:color/transparent" 
     android:padding="10dp" 
     android:scrollbarStyle="outsideOverlay"/> 

편집 2 "= 패딩 : 항목 사이의 수직 공간을 제어하는 ​​분배기 ="10dp "을, 안드로이드 사용 :

편집 한 내 질문에 대한 답이 로이드 (내 ListView를 위해) 추가함으로써 해결 10dp "는 모든 항목의 왼쪽/오른쪽과 첫 번째 항목과 마지막 항목의 위/아래에 동일한 공간을 갖습니다. android : scrollbarStyle = "outsideOverlay"를 사용하여 세로 스크롤 막대가 목록 항목 위에 겹치지 않도록하십시오. android : width = "20dp"from background_with_shadow.xml

@Shubhang Malviya 접근법을 테스트하고 나중에 결과를 추가하겠습니다.

답변

4

당신이 CardView을 살펴본 적이, 여기가 당김이를 정의하여 레이아웃 스타일을 추가 당신이 그 (것)들에게

반올림 수 있습니다함으로써

enter image description here

3

같은 UI를 만들 것이라고 official tutorial입니다 :

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="3dip" android:color="#B1BCBE" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

과 backround에 오에 위의 스타일을 추가 F 레이아웃

android:background="@drawable/your_above_syle" 

또 다른 방법은 반올림과 레이아웃에 그림자를 추가 할 수있는이 이미지를 사용하여 예를 들어 당신의 레이아웃의 배경 9 개 패치 이미지를 추가

9 patch sample image