2012-09-06 4 views
0

좋아요, 나는 좋은 영어를 말하지 않으므로 내가 원하는 것을 설명하기가 어려울 것입니다.보이는 단추를 보이지 않는 단추 위로 이동합니다.

나는 Buttons

<LinearLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:padding="10dp"> 

     <Button android:id="@+id/button_ok" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_marginRight="5dp" 
       android:background="@drawable/dialog_button_background_selector" 
       style="@style/text_big_bold_inverted" 
       android:text="@string/ok"/> 

     <Button android:id="@+id/button_cancel" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:layout_marginRight="5dp" 
       android:background="@drawable/dialog_button_background_selector" 
       style="@style/text_big_bold_inverted" 
       android:text="@string/cancel"/> 

    </LinearLayout> 

이 지금 가끔 만 확인 Button 필요와 안드로이드에서 사용자 지정 대화 상자를 가지고 있고 나는이 Button이 보이지 않는 취소합니다. 하지만 OK Button은 왼쪽에 있으며 다른 쪽이 보이지 않을 때 Button을 가운데로 이동할 수 있습니까?

.setGravity을 사용해 보았지만 작동하지 않았습니다.

답변

2

취소 버튼의 표시 여부를 View.VISIBLE 대신 View.GONE으로 설정하십시오.

1

먼저 android:layout_gravity="center_horizontal"을 LinearLayout에 설정하십시오.

그런 다음 View.INVISIBLE 대신 Button에 View.GONE을 사용하십시오.

button.setVisibility(View.GONE); 
관련 문제