5

Android에서 레이아웃 (XML 파일)을 만들고 있습니다. 2 개의 아이 뷰 (화면의 오른쪽에 1 개, 왼쪽에 1 개) 오른쪽에있는보기가 미리 결정된 공간 (dp로)을 차지하고 왼쪽에있는보기가 나머지 공간을 한도까지 차지하게하고, 그 지점에서 확장이 중지되고 두 레이아웃이 화면이 커질수록 더 멀리 움직입니다.왼쪽에 미리 설정된 공간과 뷰를 차지하는 오른쪽의보기가있는 Android 레이아웃은 일정한 한도까지 화면의 나머지 부분을 채 웁니다.

이상한 점은 오른쪽의보기가 펼쳐지는 것이고 왼쪽의보기가 미리 설정된 공간을 차지하기를 원한다면 매우 쉽다는 것입니다. 각 너비를 원하는 너비로 설정하면 (수평 선형 레이아웃에서) 안드로이드는 두보기가 맞지 않을 경우 왼쪽에있는 것을 자동으로 축소합니다.

하나의 레이아웃 파일에서이 작업을 수행하고 싶습니다. 이 레이아웃은 이미 sw512dp-land와 sw765dp-land 사이의 디스플레이 용으로 설계되었습니다.

안드로이드가 왼쪽에서 레이아웃을 축소 할 수있는 방법을 찾으면 아래 코드가 작동합니다 (레이아웃이 둘 다 지정된 크기에 맞지 않을 때). 그러나 기본적으로 시스템은 우선 레이아웃을 축소합니다. 나는에 레이아웃이 필요하지 않은 경우

(@Lokesh에서)이 코드

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" > 

<RelativeLayout 
    android:id="@+id/left" 
    android:layout_width="150dip" 
    android:layout_height="fill_parent" 
    android:background="@color/red" > 
</RelativeLayout> 

<LinearLayout 
    android:id="@+id/right" 
    android:layout_width="100dip" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:background="@color/green" > 
</LinearLayout> 

작동 것이 특정 지점에서 확대 중지 떠났다. 사람이 그래서 난 실용적으로 그 일을하거나 레이아웃에 대한 나의 접근 방식의 변화에 ​​의존 할 수없는 생각하면

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

<LinearLayout 
    android:id="@+id/left" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_toLeftOf="@+id/right" 
    android:background="@color/red" > 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/right" 
    android:layout_width="100dip" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:background="@color/green" > 
</LinearLayout> 

또한 알고 좋을 것이다.

감사합니다.

+0

당신이 말하는이 뷰 *가 정확히 무엇입니까? 레이아웃 또는 위젯을 의미합니까? –

+0

게시 코드 – Chaitanya

+0

시도하기 쉬워야하지만, 남아있는 모든 공간을 최대 한도까지 * 차지하는 것이 무엇을 의미하는지에 따라 달라집니다. – Luksprog

답변

3

나를 위해 작동합니다. 100dip으로 올바른 레이아웃을 설정 했으므로 필요에 따라 변경하십시오.

<?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="fill_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/left" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_toLeftOf="@+id/right" 
     android:background="@color/red" > 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/right" 
     android:layout_width="100dip" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@color/green" > 
    </LinearLayout> 

</RelativeLayout> 

편집 1 : 난 그냥 분명히 레이아웃을 보여 배경색을 사용했다. 전혀 필요하지 않습니다. :)

편집 2 : 만 제한 개까지 왼쪽 레이아웃을 확장 할 수있는 방법은 다음이 시도하려는 경우 - 다음은 inner 레이아웃에 위젯을 배치해야

<?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="fill_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/left" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_toLeftOf="@+id/right"> 
     <LinearLayout 
          android:id="@+id/inner" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent"   
      android:background="@color/yellow"> 

      <TextView 
       android:id="@+id/myTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This will expand only to a limit" 
       android:maxWidth="300dip" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:background="@color/red" /> 

     </LinearLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/right" 
     android:layout_width="100dip" 
     android:layout_height="fill_parent" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@color/green" > 
    </LinearLayout> 

</RelativeLayout> 

과이 무엇을이다 다른 화면처럼 보입니다.

3.1in의 HVGA 3.2in HVGA

5.2in의 QVGA 사용 5.2in QVGA

색상 : 빨강 (# FFFF00), 노란색 (#의 FFFFFF00), 녹색 (#의 FF00FF00).

+0

감사합니다.이 레이아웃 ID를 주 게시물에 참조로 추가했습니다. 이 문제는 화면이 커지면서 왼쪽의 레이아웃이 확장을 멈추지 않는다는 것입니다. 왼쪽의 레이아웃에 딥 (dip) 값이 지정되면 펼치기가 중지되면 두 레이아웃 사이의 간격이 아니라 화면의 왼쪽에서 멀리 이동합니다. – zjuhasz

+0

직접 원하는 것을 얻을 수 있는지 확신 할 수 없지만 레이아웃에 '위젯'을 배치하면 내부 레이아웃을 왼쪽에 'wrap_content'로 배치 한 다음 '위젯'을 ' 'android : maxWidth'. 잠깐, 내 대답을 편집하겠습니다. –

+0

영리하다, 나를 위해 일한다, 고맙다 alot! – zjuhasz