2011-09-06 2 views
0

4 개의 레이아웃이 사용되는 xml 파일을 이미 만들었습니다. 이제 3 차원과 4 차원 레이아웃 사이에 선형 레이아웃을 표시하고 싶습니다 .i는이 새로운 레이아웃의 너비를 0dp로 설정했습니다.이 레이아웃은 내 앱이 시작될 때 너비가 "내용 줄 바꾸기"로 변경되기를 원합니다.내 앱을 실행할 때 선형 레이아웃보기가 표시되지 않습니다.

난 다음에 다음 코드

LinearLayout layout = (LinearLayout)base.findViewById(R.id.layout);  
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( 
      LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
    Log.w(TAG, "layout " +layout); 
    layout.setLayoutParams(params); 

를 사용하여 시도는 XML 파일 내 레이아웃입니다

<LinearLayout android:layout_width="fill_parent" android:id="@+id/layout" 
android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" android:layout_height="0dp" 
    > 
    <Button android:id="@+id/button1" android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" android:layout_width="wrap_content" 
     android:text="NO" 
     android:layout_marginLeft="50dp" 
     android:layout_marginTop="64dp"></Button> 
    <Button android:id="@+id/button2" 
     android:layout_alignParentRight="true" android:layout_height="wrap_content" 
     android:layout_width="wrap_content" android:text="YES" 

     android:layout_marginRight="50dp" 
     android:layout_marginTop="64dp"></Button> 
</LinearLayout> 

하지만 레이아웃 값이 될 수있는 방법을 누군가가 말해 줄래 널 .. 여기에 소요 해결 .. ??? 미리 감사드립니다.

+1

표시하십시오 : 1) ID가 'layout'인 XML 파일과 2)'base'를로드하는 방법을 보여주십시오. –

+0

코드의이 부분이 쓰여지는 방식으로 기본이 뷰로 사용됩니다 .. – JKV

+0

질문을 다시 읽은 후, 총 5 개의 레이아웃으로 시작해서 3 번째와 4 번째 행을 설정할 수 없었습니다. 당신의 XML에서 visibility = "gone"을 찾으십시오 - 당신이 그걸 보여주고 싶다면'visibility = "visible"을 설정하십시오. 이렇게하면 크기/레이아웃 매개 변수를 사용하여 아무 것도 할 필요가 없습니다. –

답변

1

아마 안드로이드 스키마와 높이가 누락되었을 수 있습니다. 이것을 시도하십시오

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout android:layout_width="fill_parent" android:id="@+id/layout" 
android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <Button android:id="@+id/button1" android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" android:layout_width="wrap_content" 
     android:text="NO" 
     android:layout_marginLeft="50dp" 
     android:layout_marginTop="64dp"></Button> 
    <Button android:id="@+id/button2" 
     android:layout_alignParentRight="true" android:layout_height="wrap_content" 
     android:layout_width="wrap_content" android:text="YES" 

     android:layout_marginRight="50dp" 
     android:layout_marginTop="64dp"></Button> 
</LinearLayout> 
0

높이를 "0dip"으로 입력했기 때문일 수 있습니다. android : layout_height = "0dp".

"wrap_content"으로 변경하고 시도해보십시오.

관련 문제