2015-11-26 4 views
1

Я столкнулся с проблемой, что в моем Compose.xml есть вложенное LinearLayout в свитке, но когда я запускаю свиток приложений не работает:Уплотненный LinearLayout не работает в Scrollview

<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" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

+0

Может кто-нибудь помочь –

+1

Вы уверены, что содержимое Scrollview являются достаточно высокими, чтобы иметь возможность прокрутки? То есть, вы уверены, что некоторые из ваших кнопок на самом деле скрыты на дне, когда он начинается? –

+0

Если я продлеваю действие, то оно будет выполняться префектно, но если я exdend фрагмент, это не сработает. –

ответ

-1

ScrollView может иметь только один ребенок. Вы можете поместить эти макеты в один линейный макет, тогда ваш просмотр прокрутки будет работать.

Подробнее читайте android documentation.

+0

Вы можете поместить эти макеты в один линейный макет, а затем ваш рабочий файл прокрутки –

3

Его прокрутка в моем устройстве Moto X2 Ваш код не содержит ошибок, но требуется слишком много времени для загрузки. Вы можете увидеть полосу прокрутки справа на скриншоте ниже.

You can see scrollbar at right side in screenshot

Так что не использовать слишком много раскладки без необходимости. Больше макетов потребуется больше времени для загрузки данных, Вы можете также использовать Single Линейное расположение и поставить все кнопки в этот макет

Вы можете написать свой код так:

<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" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 
     android:orientation="vertical" > 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="erfer" /> 

    </LinearLayout> 
</ScrollView> 
+1

Чувак благодарит вас за интерес, но я хочу, чтобы этот макет отображался в действии ни в фрагменте. В действии он будет работать, но в Фрагменте это не будет работать –

+1

Я проверил ваш и мой код на активность и фрагмент. Оба кода работают хорошо. –

+1

Я использую android.support.v4.app.Fragment –

0

Попробуйте этот путь

<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" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     android:orientation="vertical" > 



      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 

      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 


      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="erfer" /> 

    </LinearLayout> 
</ScrollView> 
2

Прежде всего, зачем вам так много линейных лотов? Попробуйте использовать один вложенный LinearLayout и поместите все кнопки в него один за другим. Вот псевдокод.

<ScrollView> 
<LinearLayout> 
<Button/> 
<Button/> 
... 
<Button/> 
</LinearLayout> 
</Scrollview> 

Кроме того, если это не поможет, попробуйте удалить этот

android:fillViewport="true" 
Смежные вопросы