2012-09-02 2 views
0

목록보기 항목의 네 구석에 4 개의 물체를 놓으려고합니다. 상대 레이아웃을 사용하고 있습니다. 어떤 이유로 개체가 왼쪽에만 정렬됩니다. 2 개의 물체가 오른쪽에 있어야합니다. layout_gravity도 사용하고 있지만 사용하지는 않습니다. 그들은 모두 왼쪽에 정렬됩니다. 내가 교체하는 경우 :안드로이드 RelativeLayout 모서리에 물체 넣기

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/distancebackground" 
      android:layout_alignParentTop="true" /> 

     <TextView 
      android:id="@+id/distanceWindow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" /> 
    </RelativeLayout> 

이 include_time_window

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:src="@drawable/distancebackground" /> 

<TextView 
    android:id="@+id/timeWindow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="123"/> 

편집을 포함 include_distance_window.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <include 
     android:id="@+id/fromDistanceWindowLayout" 
     android:layout_alignParentLeft="true" 
     android:layout_gravity="left" 
     layout="@layout/include_distance_window" /> 

    <include 
     android:id="@+id/toDistanceWindowLayout" 
     android:layout_alignParentRight="true" 
     android:layout_gravity="right" 
     layout="@layout/include_distance_window" /> 

    <include 
     android:id="@+id/fromTimeWindowLayout" 
     android:layout_alignParentLeft="true" 
     layout="@layout/include_time_window" /> 

    <include 
     android:id="@+id/toTimeWindowLayout" 
     android:layout_alignParentRight="true" 
     layout="@layout/include_time_window" /> 

은 다음과 같습니다 두 번째는 포함 된 XML의 내용을 모두 포함하여 잘 작동합니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/distancebackground" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/distanceWindow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 
</RelativeLayout> 

왜 그런지 궁금합니다.

답변

1

내가 지적하고 싶은 한 가지. 레이아웃 중력은 상대 레이아웃에 영향을 미치지 않습니다. 선형 레이아웃의 매개 변수입니다. 둘째, Eclipse IDE를 사용하고 있다면 그래픽 레이아웃을 확인하십시오. 상대적인 레이아웃을 모두 볼 수 있는지 알고 싶습니다. 내 생각 엔 Relative Layouts에 랩 (wrap) 컨텐츠를 제공하는 대신 70dp와 같은 명확한 값을 입력 해 볼 수 있습니다. 이것들을 시험해보고 변경 사항을 알려주십시오.

+1

스마트 변경. 그렇습니다, 그것은 차이를 만들어 냈습니다. 아이들은 구석에서 시작했습니다. 그리고 예, 중력은 아무런 차이를 만들지 않았습니다. – Siddharth

+0

나는 이제 막 비슷한 것을 마쳤다. 기꺼이 도와주세요 : D. 타이밍과 상황. –