2016-04-02 6 views
0

У меня есть LinearLayout и динамически созданные элементы в нем. Мне нужно сделать его прокручиваемым, если его высота будет больше 0,8 высоты экрана. Я пытаюсь сделать это так. Где моя ошибка?ScrollView внутри RelativeLayout не работает

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" android:layout_height="match_parent" 
     android:id="@+id/layoutContainer" android:orientation="vertical" 
     android:baselineAligned="false" android:weightSum="1"> 


      <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:scrollbars="vertical" 
       android:layout_weight="0.85" > 
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:id="@+id/alarmsLayout" android:orientation="vertical" 
       android:layout_marginTop="70dp" > 
      </LinearLayout> 
      </ScrollView> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="0.15"> 
      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/addAlarmBtn" 
       android:src="@drawable/time" 
       android:layout_marginBottom="15dp" /> 
     </LinearLayout> 
    </LinearLayout> 
+0

Ваш относительный вес макета в 1 не 0,8, а также изменить высоту Scrollview на wrap_content. Также нет родительского макета. как с весом attr, вы должны иметь линейный макет как родительский –

+0

, вы используете LinearLayout в качестве родительского макета? Если да, то какой у вас весовой вес? –

+0

просто установите прослушиватель на scrollview следующим образом: [onTouchlistener] (http://stackoverflow.com/questions/34916506/animated-expandablelistview-in-scrollview/34916626#34916626) – pratik

ответ

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layoutContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1" 
    android:baselineAligned="false" 
    android:orientation="vertical" > 


     <ScrollView 
      android:layout_weight="0.8" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:scrollbars="vertical" > 

      <LinearLayout 
       android:id="@+id/alarmsLayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="70dp" 
       android:orientation="vertical" > 
      </LinearLayout> 
     </ScrollView> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.15" > 

     <ImageView 
      android:id="@+id/addAlarmBtn" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="15dp" 
      android:src="@drawable/background_button" /> 
    </RelativeLayout> 

</LinearLayout> 
+0

Где вы взяли этот код? У меня есть два RelativeLayouts. В первом случае у меня есть scrollView, а во втором - ImageView –

+0

Вам не нужно два относительных макета. Одного достаточно –

+0

Размер ImageView в вашем коде - это полный экран. –

0
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width"match_parent" 
    android:layout_height="match_parent"> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" > 

      <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/alarmsLayout" android:orientation="vertical" 
      android:layout_marginTop="70dp" > 
      </LinearLayout> 

     </ScrollView> 

    <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginBottom="15dp"> 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/addAlarmBtn" 
      android:src="@drawable/time" /> 
    </RelativeLayout> 

</RelativeLayout> 
0

Попробуйте использовать этот

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width ="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width ="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.8"> 

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:scrollbars="vertical" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/alarmsLayout" android:orientation="vertical" 
    android:layout_marginTop="70dp" > 
</LinearLayout> 

</ScrollView> 
</RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_marginBottom="15dp" 
    android:layout_height="0dp" 
    android:layout_weight="0.2" 
    android:gravity="center"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/addAlarmBtn" 
    android:src="@drawable/badge" /> 
</RelativeLayout> 

    </LinearLayout> 
Смежные вопросы