2012-04-25 6 views
44

안에있는 LinearLayout 내의 여러 항목에 레이아웃 가중치를 지정하고 싶습니다. 그러나 ScrollViewLinearLayoutweightSum을 무시합니다.레이아웃 가중치가 ScrollView 내에서 작동하지 않습니다.

목표는 2, 1, 1의 가중치로 레이아웃을 나누는 것입니다 (총 합계는 4). 그러나 이는 ScrollView 내부에서 올바르게 작동하지 않습니다.

이 레이아웃 문제를 어떻게 해결할 수 있습니까?

main.xml에

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:weightSum="4"> 

     <LinearLayout android:id="@+id/logo" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="2" 
      android:background="#FFFFFF" /> 

     <LinearLayout android:id="@+id/logo1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:background="#000000" /> 


     <LinearLayout android:id="@+id/logobutton" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="1" 
      android:background="#4B4B4B" /> 

    </LinearLayout> 
</ScrollView> 
+0

작업을하지만 –

+0

확인이 하나 작동하지 않을 것보다 내 질문시 사용있는 ScrollView 경우보다 난 단지있는 ScrollView를 제거하고 경우 : [안드로이드 레이아웃 무게 (http://stackoverflow.com/questions/4986861/를 android-layout-weight) 나는 같은 종류의 문제라고 생각한다. – user1264255

답변

137

나는 전에이 문제에 직면 해있다. ScrollView에서 android:fillViewport="true"을 사용하면 화면이 가득 차게됩니다.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" > 
+1

@MIPTECH :이 대답을 시도하십시오. romain guy의 자세한 정보 http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/ – Akhil

+2

+1 매력처럼 일하고 있습니다. 고마워요 !!! – Venky

+0

고마워, 나는 정말로 해결책을 찾고 있었고 그것이 내가 필요로하는 바로 그 것이다. –

2

당신이 그것을했던 것처럼이 작동하지 않습니다. ScrollView의 하위보기는 wrap_content으로 설정해야합니다. fill_parent으로 설정하면 ScrollView보다 크지 않으므로 ScrollView 영역을 채우고 스크롤하지 않습니다.

layout_weight의 아이디어는 비례하여 특정 영역을 채우는 것입니다.

당신은 아이의 모든 설정해야 LinearLayoutslayout_height 중 하나 wrap_content 또는 (DP)에 특정 크기로 당신이 추가

의 xmlns를 제거해야했다 부모 LinearLayoutlayout_height

wrap_content에 : android = "http://schemas.android.com/apk/res/android"

루트가 아닌 경우 (전나무 st) 요소를 사용합니다.

관련 문제