2013-08-26 3 views
0

나는 안드로이드 프로그래밍에 초보자 다. 나는 이것을 철저히 조사하려고 노력했지만이 문제를 해결하는 방법을 아직 많이 이해하지 못했다. 나는 아래 XML 코드를 포함 할 것이다. Eclipse에서 상대 레이아웃의 크기 조정을 사용하여 내 앱의 모양을 얻으려고했습니다. 간단한 레이아웃 - 제목 헤더와 가운데 3 개의 버튼. 분명히, 내가 겪고있는 문제는 설정 한 특정 차원으로 인해 모든 것을 어색하게 잡아 당기는 것입니다. "match_parent"및 "wrap_content"를 올바르게 사용하는 방법에 대한 제안 사항은 무엇입니까? 나는이 상황에서 어떻게 그들을 적용 할 수 있는지 잘 이해하지 못하고있다. 어쩌면 선형 레이아웃을 사용해야했지만 어쨌든 성능 향상을 위해 버튼 수를 3에서 9로 늘린 경우 상대 레이아웃이 더 나은 선택 인 것처럼 보였습니다. 어떤 도움을 많이 주시면 감사하겠습니다! 여기 크기가 큰 기기에서 내 콘텐츠가 늘어나지 않도록 상대 레이아웃의 크기를 적절하게 조정하려면 어떻게해야합니까?

내 XML 코드 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context=".MainActivity" 
android:background="#ffffff" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="60dip" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/pets_titlecrop" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="80dip" 
    android:layout_height="80dip" 
    android:layout_below="@+id/textView1" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="48dp" 
    android:background="@drawable/call_now" />" 


<TextView 
    android:id="@+id/textView2" 
    android:layout_width="100dip" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/textView1" 
    android:background="#808080" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="100dip" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignTop="@+id/textView2" 
    android:background="#808080" />" 



<Button 
    android:id="@+id/button3" 
    android:layout_width="80dip" 
    android:layout_height="80dip" 
    android:layout_alignLeft="@+id/button2" 
    android:layout_below="@+id/button2" 
    android:layout_marginTop="36dp" 
    android:background="@drawable/bpaw_printedit" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="80dip" 
    android:layout_height="80dip" 
    android:layout_alignLeft="@+id/button1" 
    android:layout_below="@+id/button1" 
    android:layout_marginTop="36dp" 
    android:background="@drawable/blue_globemap" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="100dip" 
    android:layout_height="30dip" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/textView3" 
    android:layout_toRightOf="@+id/textView2" 
    android:background="@drawable/by_wvg" /> 



</RelativeLayout> 
+0

WOT을 정확히 시도 원하는가? –

+0

이 레이아웃을 유지하고 싶지만 모든 안드로이드 장치에서 "범용 피팅"을 허용합니다. 이 세트로 "딥 (dip)"을 설정하면 더 큰 화면에서 어색하게 늘어납니다. – user2719019

답변

0

당신은 중첩 된 시도해야 선형 레이아웃 때문에 당신이 유연한 사용자 인터페이스를 달성 할 수 가중치를 사용하여, 당신은이

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    android:orientation="vertical" 
    tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="60dip" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#808080" /> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#808080" /> 

</LinearLayout> 

+0

내가 필요한 것 같습니다. 고맙습니다!! – user2719019

+0

heyy, 연습 해보십시오. –