2011-09-20 63 views
0

短的問題:我想要的片段,這是一個滾動視圖裏面,佔據所有可用空間。我怎樣才能做到這一點?片段的滾動型內太小

詳細信息:我有一個片段,我把滾動型內父佈局。該滾動視圖佔用父級佈局中的大部分空間。儘管如此,片段在滾動視圖內顯示得非常小。圖片說明了這一點:

the fragment, or the scroll view, doesn't take the whole space

這是片段的XML:

<?xml version="1.0" encoding="utf-8"?> 
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ImagePickerGridView" android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:gravity="center" android:stretchMode="columnWidth" 
    android:numColumns="auto_fit" android:horizontalSpacing="5dp" 
    android:verticalSpacing="5dp" android:background="@color/orange1"> 
</GridView> 

這是父佈局XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:gravity="center" android:stretchMode="columnWidth" 
    android:numColumns="auto_fit" android:horizontalSpacing="5dp" 
    android:verticalSpacing="5dp"> 
    <ScrollView android:layout_width="match_parent" 
     android:id="@+id/imagePickerScrollView" android:layout_weight="1.0" 
     android:layout_height="match_parent" android:background="@color/orange1" android:layout_gravity="fill_vertical"> 
    </ScrollView> 
    <LinearLayout android:id="@+id/linearLayout3" 
     android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:background="@color/blue1"> 
     <Button android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:layout_weight="1.0" 
      android:text="@string/ImportSelectedButton" android:id="@+id/importSelectedButton" 
      android:layout_marginLeft="@dimen/standardMargin" 
      android:layout_marginTop="@dimen/standardMargin" 
      android:layout_marginBottom="@dimen/standardMargin" android:onClick="onImportSelected"></Button> 
     <Button android:layout_height="wrap_content" 
      android:layout_width="wrap_content" android:layout_weight="1.0" 
      android:text="@string/CancelButton" android:id="@+id/cancelButton" 
      android:layout_marginRight="@dimen/standardMargin" 
      android:layout_marginTop="@dimen/standardMargin" 
      android:layout_marginBottom="@dimen/standardMargin" android:onClick="onCancel"></Button> 
    </LinearLayout> 
</LinearLayout> 

最後,這是我怎麼片段加入到活動:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.image_picker_1); 

    Log.d(CLASS_NAME, "onCreate"); 

    m_multiPicSelect = getIntent().getBooleanExtra(IntentHelper.MULTI_SELECT, false); 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 

    Fragment fragment = new ImagePickerFragment(); 
    fragmentTransaction.add(R.id.imagePickerScrollView, fragment); 
    fragmentTransaction.commit(); 
} 

回答

0

OK,我發現了什麼問題。原來,GridView滾動容器,所以沒有必要把它ScrollView內。一旦我把網格視圖放在線性佈局中,一切都奏效了!我仍然不知道爲什麼GridView會縮小到ScrollView之內,可能是因爲本來不應該在那裏:)

感謝大家的回答!

0

嘗試這種::

<ScrollView android:layout_width="fill_parent" 
     android:id="@+id/imagePickerScrollView" android:layout_weight="1.0" 
     android:layout_height="fill_parent" android:background="@color/orange1" android:layout_gravity="fill_vertical"> 
    </ScrollView> 
+0

不,這是行不通的。不過,我想我找到了答案。我沒有意識到GridView本身是一個可滾動的容器!我會在一分鐘後發佈解決方案。謝謝! – Macondo2Seattle

0

...作爲@nik說,還要加android:fillViewport="true"

+0

謝謝!事實證明,問題是將GridView放入ScrollView中。我在一個單獨的答案中解釋這一點。 – Macondo2Seattle