2014-09-13 3 views
1

일부 안드로이드 응용 프로그램의 상대 레이아웃을 사용하려고합니다.android 모든 장치의 RelativeLayout

<Button 
     android:layout_width="100dip" 
     android:background="#ff394aff" 
     android:text="start" 
     android:layout_height="wrap_content" 

     android:layout_marginLeft="225dp" 
     android:layout_marginTop="225dp" 

     android:id="@+id/start" android:layout_gravity="center_horizontal" android:layout_weight="0.50"/> 

그러나 일부 장치에서는 다른 위치에 표시됩니다. 나는 "dip"과 "sp"를 시도했지만 문제는 남아 있습니다. 모든 기기에서 위치가 동일하도록하는 방법을 알려주세요.

+0

버튼 변경 또는 상대적 위치 변경 위치? – MHP

+0

단추의 위치 : | – user3879782

답변

0

marginleft를 사용할 때 나는 얻지 못했고, 왜 중력을 사용하여 중점을 수평으로 배치 했습니까? 이 장치를 사용하면 화면의 전체 너비가있는 페이지 하단에 버튼이 표시됩니다. 이 XML에서는 하단에 고정되어있는 뒤로 버튼이있는 listview를 볼 수 있습니다. 테스트 한 결과, 목록의 위치에 원하는 것을 넣을 수 있고 이에 따라 버튼 위치를 조정할 수 있습니다. 이것이 도움이 될 수 있기를 바랍니다.

<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="wrap_content" 
android:orientation="vertical" 
android:paddingBottom="1dip" 
android:paddingLeft="1dip" 
android:paddingRight="1dip" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="150dip" 
    android:layout_above="@+id/cback" 
    android:layout_alignParentTop="true" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:drawSelectorOnTop="false" /> 
</LinearLayout> 

<Button 
    android:id="@+id/cback" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/btn_black" 
    android:text="Back" 
    android:textColor="#ffffff" 
    tools:ignore="HardcodedText" /> 

</RelativeLayout> 
0

많은 장치의 해상도가 다르므로 코드의 문제는 marginleft 및 margintop입니다. 이로 인해 버튼 위치가 모든 기기에서 다릅니다. 또한 android : layout_weight = "0.50"은 상대 레이아웃에서 사용하면 안됩니다. 아무런 영향을 미치지 않습니다.

+0

OK! 그래서 위치에 버튼을 수정하는 방법. 독립적 인 해결책? – user3879782

+0

android : layout_centerHorizontal = "true" android : layout_centerInParent = "true" android : layout_centerVertical = "true"버튼을 배치 할 때이 속성을 사용할 수 있습니다. 또는 원하는 지원을위한 dimens.xml을 만들려고합니다. –