2011-12-27 2 views
1

안드로이드 레이아웃에서 3 개의 객체를 가로로 정렬하려면 첫 번째 객체가 왼쪽에 정렬되어야하고 세 번째 객체가 오른쪽에 나타나야하고 두 번째 객체가 가운데에 나머지 너비를 가져야합니다.안드로이드 레이아웃에서 3 개의 객체를 수평으로 설정하는 방법

어떻게 만들 수 있습니까?

+1

왜 투표를 했습니까? – Adham

+1

귀하의 질문에 연구 노력이 나타나지 않았기 때문에. 이것은 거의 모든 곳에서 문서화 된 기본적인 Android 제품입니다. –

+2

왼쪽 및 오른쪽 오브젝트에 상대적 레이아웃 및 중력을 사용하십시오. –

답변

7

합니다. TextView를 원하는보기로 바꾸면됩니다. 크리스마스이기 때문에 배경을 빨강으로 만들었습니다.

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


    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView" android:background="#f00"/> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="TextView" android:background="#f00"/> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:text="TextView" android:background="#f00"/> 

</LinearLayout> 
1

This은 찾고있는 예입니다. Linearlayout의 텍스트 뷰를 변경하여 원하는 객체를 만족시킵니다. 객체를 넣는 방법을 모르는 경우 This 참조 코드를 삽입 할 ID 메소드를 찾으십시오.

1

가로 방향의 선형 레이아웃이 필요합니다. 그 후 당신의 세 개의 객체를 선언하고 그들에게 일 각각의 가중치를 부여 : 안드로이드 : 이것은 꽤 많이 당신이 원하는 무엇에 layout_weight = "1"

Linear Layout and weight in Android

+0

당신은 여기에 틀림 없습니다. 모든 무게 1을 주어 똑같이 물체를 분배하게됩니다. – MrJre

+0

@mrjre 글쎄, 그게 내가 질문을 읽는 방법이다. – barry

관련 문제