2011-02-24 4 views
1

아래 첨부 이미지와 같은 레이아웃을 준비하려고합니다.android - 레이아웃의 문제

내 문제 는 이미지에 표시됩니다 : 이미지

  • 1로 표시된

    1. 은 내가 취소 "설정"저장 "을하려고 설정하는 버튼 정확히 같은 (폭) 시도 "버튼을 누르십시오. 나는 아래의 XML 레이아웃을 시도

      enter image description here

  • :

    <RelativeLayout 
        android:id="@+id/widget38" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:padding="5dp"> 
    
        <TextView 
         android:layout_width="wrap_content" 
         android:id="@+id/textView1" 
         android:text="Event" 
         android:layout_alignParentLeft="true" 
         android:layout_height="wrap_content"> 
        </TextView> 
    
        <EditText 
         android:layout_width="fill_parent" 
         android:id="@+id/editText1" 
         android:layout_alignParentLeft="true" 
         android:hint="Tap to enter title" 
         android:layout_marginTop="5dp" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/textView1"> 
        </EditText> 
    
        <View 
         android:id="@+id/separator"   
         android:background="#ffffff"   
         android:layout_width = "fill_parent" 
         android:layout_height="1dip" 
         android:layout_centerVertical ="true" 
         android:layout_below="@+id/editText1"/> 
    
        <TextView 
         android:layout_width="wrap_content" 
         android:id="@+id/textView2" 
         android:text="From" 
         android:layout_alignParentLeft="true" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/separator" 
         android:layout_marginTop="5dp"> 
        </TextView> 
    
        <Button 
         android:layout_width="wrap_content" 
         android:id="@+id/button1" 
         android:layout_alignParentLeft="true" 
         android:text="Button" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/textView2"> 
        </Button> 
    
        <Button 
         android:layout_width="wrap_content" 
         android:id="@+id/button2" 
         android:text="Button" 
         android:layout_marginLeft="10dp" 
         android:layout_alignTop="@+id/button1" 
         android:layout_height="wrap_content" 
         android:layout_toRightOf="@+id/button1" 
         android:layout_below="@+id/button1"> 
        </Button> 
    
        <View 
         android:id="@+id/separator1"   
         android:background="#ffffff"   
         android:layout_width = "fill_parent" 
         android:layout_height="1dip" 
         android:layout_centerVertical ="true" 
         android:layout_below="@+id/button2"/> 
    
        <TextView 
         android:layout_width="wrap_content" 
         android:id="@+id/textView3" 
         android:text="To" 
         android:layout_alignParentLeft="true" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/separator1" 
         android:layout_marginTop="5dp"> 
        </TextView> 
    
        <Button 
         android:layout_width="wrap_content" 
         android:id="@+id/button3" 
         android:layout_alignParentLeft="true" 
         android:text="Button" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/textView3"> 
        </Button> 
    
        <Button 
         android:layout_width="wrap_content" 
         android:id="@+id/button4" 
         android:text="Button" 
         android:layout_marginLeft="10dp" 
         android:layout_alignTop="@+id/button3" 
         android:layout_height="wrap_content" 
         android:layout_toRightOf="@+id/button3" 
         android:layout_below="@+id/button3"> 
        </Button> 
    
        <RelativeLayout 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/relativeLayout1" 
         android:layout_alignParentBottom="true"> 
    
         <Button android:layout_width="wrap_content" android:id="@+id/button5" android:layout_alignParentBottom="true" android:text="Save" android:layout_height="wrap_content"></Button> 
         <Button android:layout_width="wrap_content" android:id="@+id/button6" android:layout_alignParentBottom="true" android:text="Cancel" android:layout_height="wrap_content" android:layout_toRightOf="@+id/button5"></Button> 
        </RelativeLayout> 
    
    
    </RelativeLayout> 
    
    +4

    나는 * 당신이 * 질문 * 할 생각이 없습니다. – SK9

    +1

    그는 자신의 레이아웃이 이미지의 레이아웃과 일치하기를 원합니다. 나에게 똑바로 보인다. –

    +0

    OP에 레이아웃 XML의 결과로 레이아웃 이미지를 게시 할 수 있다면 도움이 될 것입니다. –

    답변

    1

    당신은 여기 android:layout_weight

    를 사용하여 버튼의 무게을 조정할 수 있습니다 .XML 레이아웃 파일에서 사용자 버튼에 "무게"값을 설정해야 할 것은 그것을 사용하는 방법의 예 : http://android.amberfog.com/?p=328 '이미지 1'로 표시된 버튼에 대한

    +0

    나는 아래의 "Save/Cancel"버튼에 대한 아이디어를 얻었고, 너비를 0dp로 설정 한 다음 두 버튼에 모두 weight = 1로 설정했습니다. –

    +0

    위대한 지원을위한 고맙습니다, 이제 상단 bottons 문제에 다시 시도해 보겠습니다. –

    +0

    고 버튼에 대해 많이 고맙습니다. android : layout_width = "wrap_content"(두 버튼 모두) android : layout_weight = "1" 첫 번째 버튼과 옆에있는 버튼 (오른쪽) "0". –

    0

    당신은 수평 선형 레이아웃을 사용할 수 있습니다. 첫 번째 문제를 들어 당신이

    1

    당신은 같은 고정 폭을 설정할 수 있습니다 '16dip'즉 당신이 추가 할 수 있습니다 아래의 버튼에 대한

    <Button 
         android:layout_width="16dip" 
         android:id="@+id/button1" 
         android:layout_alignParentLeft="true" 
         android:text="Button" 
         android:layout_height="wrap_content" 
         android:layout_below="@+id/textView2"> 
        </Button> 
    

    있는 LinearLayout에 수평으로 나는 당신의 문제는 당신이 당신의 XML 코드와 동일하지 않습니다 있다고 생각 0 폭과 중량 값

    <Button 
          android:layout_width="0dip" 
          android:layout_weight="1" 
          android:id="@+id/button4" 
          android:text="Button" 
          android:layout_marginLeft="10dp" 
          android:layout_alignTop="@+id/button3" 
          android:layout_height="wrap_content" 
          android:layout_toRightOf="@+id/button3" 
          android:layout_below="@+id/button3"> 
         </Button> 
    
    +0

    +1, 고맙습니다 지원, 나는 해결책을 가지고 있고 그 잘 작동, 같은 길이와 하단 막대에 "저장/취소"버튼을 가지고 있습니다. 자, 저는 여러분의 솔루션으로 위의 버튼을 시도 할 것입니다. 위 코드를 수정하십시오. button id는 "button4"대신 "button5"입니다. –

    +0

    그러나 "200dp"및 "50dp"로 상위 botton에 고정 설정하려고했습니다.외관이 좋고 작은 화면에 잘 어울립니다. 그러나 대형 화면에서 테스트 할 때 오른쪽면이 비어 있습니다. 그러니 제발 도와주세요. –

    +0

    상단 버튼의 경우 @Phonon이 제공하는 링크에서 아이디어를 얻었습니다. 두 버튼 모두에 대해 android : layout_width = "wrap_content"를 수행했고, 첫 번째 버튼에는 android : layout_weight = "1" 두 번째 버튼. –

    0

    으로 지향? 당신이 버튼 (사진에 취소 및 유효 버튼) 같은 곳을 원하는 경우

    당신은) (당신이 활동의에서 onCreate에서 예를 들어 모두

    0

    android:layout_weight="1"을 넣어야의 android:layout_weight

    를 사용해야합니다 메소드를 설정 한 후 다음을 수행하십시오.

    findViewById(R.id.button1).setWidth(findViewById(R.id.button5).getWidth()); 
    findViewById(R.id.button2).setWidth(findViewById(R.id.button6).getWidth()); 
    

    이게 작동하는지 알려주세요.

    관련 문제