카테고리 보관물: 안드로이드

안드로이드

안드로이드에서 listView 항목 사이에 공백을 설정하는 방법 그렇다면 구체적인 방법이

listView Item에서 marginBottom을 사용하여 listView Item 사이에 공간을 만들려고했지만 여전히 항목이 서로 붙어 있습니다.

가능합니까? 그렇다면 구체적인 방법이 있습니까?

내 코드는 다음과 같습니다

<LinearLayout
android:id="@+id/alarm_occurences"
android:layout_width="fill_parent" 
android:orientation="vertical"
android:layout_height="fill_parent"
android:background="#EEEEFF"
xmlns:android="http://schemas.android.com/apk/res/android">

<ListView
android:id="@+id/occurences"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

내 맞춤 목록 항목 :

<com.android.alarm.listItems.AlarmListItem
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="@drawable/alarm_item_background"
android:layout_marginBottom="10dp"    
>
<CheckedTextView     
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="serif"
    android:padding="10dp"

/>

</com.android.alarm.listItems.AlarmListItem>

이 경우 목록 항목 사이에 간격을 두려면 어떻게해야합니까?



답변

@Asahi는 머리에 못을 박았지만 나중에 Google을 통해 여기에 떠 다니는 사람을 위해 약간의 XML을 추가하고 싶었습니다.

<ListView android:id="@+id/MyListView"
  android:layout_height="match_parent"
  android:layout_width="match_parent"
  android:divider="@android:color/transparent"
  android:dividerHeight="10.0sp"/>

어떤 이유로 “10”, “10.0”및 “10sp”와 같은 값은 모두 dividerHeight값으로 거부됩니다 . 부동 소수점 숫자와 “10.0sp”와 같은 단위를 원합니다. @Goofyahead 메모와 마찬가지로이 값에 디스플레이 독립적 픽셀을 사용할 수도 있습니다 (예 : “10dp”).


답변

아마도 divider또는 dividerHeight속성이 ListView문제를 해결할 수 있습니다.


답변

Nik Reiman의 솔루션은 작동하지만, 내가하고 싶은 일에 최적의 솔루션이 아니라는 것을 알았습니다. 디바이더를 사용하여 여백을 설정하면 디바이더가 더 이상 보이지 않아 항목 사이에 명확한 경계를 표시하는 데 사용할 수없는 문제가있었습니다. 또한 각 항목에 더 많은 “클릭 가능 영역”을 추가하지 않으므로 항목을 클릭 가능하게 만들고 항목을 얇게 만들려면 분배기가 추가 한 높이가 아니므로 누구나 항목을 클릭하기가 매우 어렵습니다. 품목의 일부.

다행히도 나눗셈을 표시하고 여백이 아니라 패딩을 사용하여 각 항목의 높이를 조정할 수있는 더 나은 솔루션을 찾았습니다. 예를 들면 다음과 같습니다.

목록보기

<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

ListItem

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="10dp"
    android:paddingTop="10dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Item"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

답변

예를 들어 다른 레이아웃으로 ListView아이템을 감싸고 여백을 추가해야합니다 .your_listview_itemLinearLayoutyour_listview_item

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <your_listview_item
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
    ...
    ...
    />
</LinearLayout>

이렇게하면 필요한 경우 ListView항목 의 오른쪽과 왼쪽에 공간을 추가 할 수도 있습니다 .


답변

더 많은 공간을 추가하지만 수평선을 유지하는 솔루션 divider.xmlres/drawable폴더 를 추가 하고 내부에 선 모양을 정의하는 것입니다.

divider.xml

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

    <stroke
        android:width="1px"
        android:color="@color/nice_blue" />

</shape>

그런 다음 내 목록에서 다음과 같이 분배기를 참조합니다.

<ListView
    android:id="@+id/listViewScheduledReminders"
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_marginBottom="@dimen/mediumMargin"
    android:layout_weight="1"
    android:divider="@drawable/divider"
    android:dividerHeight="16.0dp"
    android:padding="@dimen/smallMargin" >

</ListView>

을 알 android:dividerHeight="16.0dp"증가와 나는 기본적으로 구분선의 상단과 하단에 대한 자세한 패딩을 추가하고이 높이를 감소시켜.

이 페이지를 참조 용으로 사용했습니다 : http://developer.android.com/guide/topics/resources/drawable-resource.html#stroke-element


답변

나누기와 여백을 나누지 않고 나누기를 표시하려면 InsetDrawable을 사용하십시오 (크기는 @Nik Reiman의 형식이어야 함).

목록보기:

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:cacheColorHint="#00000000"
    android:divider="@drawable/separator_line"
    android:dividerHeight="10.0px"/>

@ 드로어 블 / 분리기 _ 라인 :

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="5.0px"
    android:insetRight="5.0px"
    android:insetTop="8.0px"
    android:insetBottom="8.0px">

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:startColor="@color/colorStart"
            android:centerColor="@color/colorCenter"
            android:endColor="@color/colorEnd"
            android:type="linear"
            android:angle="0">
        </gradient>
    </shape>
</inset>

답변

당신이 사용할 수있는:

android:divider="@null"
android:dividerHeight="3dp"

예:

<ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView" android:layout_gravity="center_horizontal"
        android:dividerHeight="3dp"
        android:divider="@null" android:clickable="false"/>