2012-07-29 4 views
-1

좋아,이 문제는 지금 약 2 주 동안 나에게 해를 끼쳐 왔고 내가 한 모든 연구에서이 문제를 파악할 수 없습니다. 원형 차트의 형태로 6 개의 버튼이 있습니다. 내가 XML로 레이아웃을 만들 때, 나는 그것들을 멋지게 만들 수있다. 내가 태블릿 크기 또는 내 모든 버튼을 이동 다른 크기의 화면으로 변경하고 끔찍한 볼어떻게 버튼을 안드로이드에서 한 곳에서 머물게 할 수 있습니까?

view I want to achieve

.

bad view

어떻게 어떤 화면 크기에서이 버튼을 고정해야합니까? approriate 폴더에서 서로 다른 이미지 크기를 가져야한다는 것을 알고 있으며이를 수행 할 계획이지만, XML 파일의 특정 위치에서이를 잠 그거나 필요한 작업을 수행 할 수있는 방법이 있는지 알아야합니다. 제대로 작동하도록하십시오. 언제나처럼 모든 도움을 주시면 대단히 감사하겠습니다. 제 질문에 대해 충분히 명확하지 않으면 어떤 질문에 대해서도 답변 드리겠습니다. 감사

여기 당신은 각 버튼에 대한 고정 DP를 제공 한 내 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:background="@drawable/mainback" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" 
    android:layout_marginLeft="25dp" 
    android:background="@drawable/ipadcollegesm" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/button1" 
    android:layout_alignRight="@+id/button1" 
    android:layout_marginBottom="92dp" 
    android:background="@drawable/ipadmusicsm" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/button2" 
    android:layout_marginLeft="5dp" 
    android:layout_toRightOf="@+id/button1" 
    android:background="@drawable/ipadfamilysm" /> 

<Button 
    android:id="@+id/button4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/button3" 
    android:layout_alignTop="@+id/button1" 
    android:background="@drawable/ipadyouthsm" /> 

<Button 
    android:id="@+id/button5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/button4" 
    android:layout_below="@+id/button3" 
    android:layout_marginTop="14dp" 
    android:background="@drawable/ipadlinkssm" /> 

<Button 
    android:id="@+id/button6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBaseline="@+id/button5" 
    android:layout_alignBottom="@+id/button5" 
    android:layout_toLeftOf="@+id/button4" 
    android:background="@drawable/ipadpodcastsm" /> 

</RelativeLayout> 
+0

귀하의 XML 레이아웃 파일을 게시하십시오. – tpow

+0

거기에 가서, 잊어 버렸고, 당신이 논평 한대로 그것을하고있었습니다. 나는 중첩 된 상대 레이아웃 프레임 레이아웃을 시도하고 그 중 하나가 제대로 작동하지 않았다 그래서이 기본 premis 내가 뭘 원하는 것입니다 – Bryan

답변

2

입니다, 다른 장치는 서로 다른 해상도를 가지고있다.

작업량이 가장 적은 여러 장치에서이 작업을 수행하려면 다른 상대 레이아웃을 루트로 추가하고 중력을 가운데로 설정하는 것이 좋습니다. 이렇게하면 레이아웃은 항상 화면 중앙에 배치됩니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center" 
android:background="@drawable/mainback"> 
    <RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

     *** Your buttons would be here *** 

    </RelativeLayout> 
</RelativeLayout> 

또 다른 방법은 각 화면 크기에 대해 dimens 파일을 사용하는 것입니다. 그러나 위의 방법은 아마도 가장 쉬운 방법 일 것입니다.

+0

단추에 아무것도 변경하거나 그냥 그들을 떠날 방법 그들에게 두 번째 상대적 배치에 중첩시켜주세요. – Bryan

+0

나는 그들이 잘되어야한다고 생각 하겠지만, 저스틴 비버 (Justin Bieber) 학자는 "절대 말하지 말라"고 말한 적이 있습니다. 아마도 FrameLayout이나 중심을 지닌 것을 추가 한 다음이를 앵커로 사용하면 더 도움이 될 것입니다. – jimmithy

관련 문제