2012-04-21 1 views
2

목록 뷰가있는 세로 형 LinearLayout과 맨 아래에 하나의 ImageView가 있고 목록 뷰는 뒤에 남겨진 공간을 채 웁니다.만드는 방법 android : layout_gravity = "bottom | center_horizontal"아래쪽에 머무름

그것은 다음과 같습니다 : I 표시 목록보기있을 때마다 그것은 잘 작동

<LinearLayout layout_height="match_parent" layout_width="@dimen/width" 
    orientation="vertical"> 
    <ImageView layout_height="@dimen/width" layout_width="@dimen/width" id="@+id/top"> 

    <ListView android:layout_height="0px" 
     android:background="#00ffff" 
     android:layout_width="@dimen/width" 
     android:layout_weight="1" /> 

    <ImageView layout_height="@dimen/width" layout_width="@dimen/width" id="@+id/bottom" layout_gravity="bottom|center_horizontal"> 

.

하지만 가시성을 없애기 위해 ListView를 설정할 때마다 맨 아래 이미지 뷰 바로 아래에 '하단'ImageView가 팝업됩니다.

내 질문은 내가 'android : layout_gravity = "bottom | center_horizontal"'라고 말했음에도 불구하고 맨 아래에 ImageView가 남아 있지 않는 이유입니다. 'hierarchViewer를 보았습니다. 상위 높이가 화면 높이와 일치합니다. 따라서 하단 이미지 뷰는 android : layout_gravity = "bottom | center_horizontal"을 존중해야하며 하단에 머물러야합니다.

+0

당신이 gone''일하기 위해'ListView'을 필요로합니까, 아니면 invisble''로 설정 멀리 얻을 수 있습니다 ? 후자가 당신이 원하는 것을 줄 것이라고 확신합니다. –

답변

3

내 의견에 대한 대안으로, 당신은 당신의 LinearLayoutRelativeLayout로 대체 할 수 있습니다. Agarwal은 이미 이것을 제안했지만 그의 코드는 다소 혼란 스럽습니다. 그리고이 글을 쓰는 시점에서 여러분이 원하는 코드가 맞지 않습니다.

아래 코드를 입력하십시오. ListViewgone으로 설정하면 상단 및 하단 이미지는 visible과 동일하게 유지됩니다. 당신이 사람들을 다시 넣어 할 수 있습니다, 그래서 나는 @dimens/width 참조를 대체 노트를 수행합니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 

    <ImageView android:id="@+id/top" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <ListView android:layout_width="fill_parent" 
     android:layout_height="fill_parent" android:layout_above="@+id/bottom" 
     android:layout_below="@+id/top" android:background="#00ffff" /> 

    <ImageView android:id="@+id/bottom" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 
+0

감사합니다. ListView를 맨 위에서 아래쪽에서 '확장'할 수 있습니까? 즉 첫 번째 요소는 ListView의 맨 아래에 표시되고 두 번째 요소는 첫 번째 요소 위에 있고 아들은 등등입니까? – michael

+0

@michael : 만약 실수가 아니라면,이 목적을 위해'stackFromBottom' 플래그를 사용할 수 있습니다. xml : ['android : stackFromBottom'] (http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:stackFromBottom) 또는 코드 : ['setStackFromBottom (boolean)']을 통해 설정하십시오. (http://developer.android.com/reference/android/widget/AbsListView.html#setStackFromBottom%28boolean%29). * "bottom에서 스택을 true로 설정하면 목록이 뷰의 맨 아래부터 내용을 채 웁니다."* –

0

가장 좋은 방법은 이것에 대한 ralaticelayout 사용하는 것입니다 ::::

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#0000FF"> 

<ImageView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/top" /> 
<ImageView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/bottom" android:layout_alignParentBottom="true"/> 
    <ListView android:layout_height="fill_parent" 
     android:background="#00ffff" 
     android:layout_width="fill_parent" 
     android:layout_below:@id/top android:layout_above:@id/bottom /> 


</RelativeLayout> 
+1

죄송합니다. 귀하의 제안은 전혀 이해가되지 않습니다. 'orientation' 속성을 가진'RelativeLayout'? 그리고 체중을 가진 아이보기? 이것은 실제로 항상'0'의 높이로'ListView'를 렌더링합니다. 즉, 전혀 보이지 않을 것입니다. 마지막으로, ListView와 아래의 ImageView가 오버레이 될 것입니다. 아마도 OP 이후의 것이 아닙니다 ... –

+0

오리 엔테이션이 제거되어 relativelayout이 필요 없습니다. 0dp는 남은 공간을 차지하고 있음을 나타냅니다. –

+0

제안을 실제로 시도해 보셨습니까? 지금까지 내가 알고있는 한 가중치는 'RelativeLayout'에서 무시됩니다. 즉, 고정 된 높이가 0으로 설정된다는 것을 의미합니다 ... –