2016-04-02 39 views
0

我有一个LinearLayout并在其中动态创建元素。如果它的高度大于屏幕高度的0.8,我需要使它滚动。我试图这样做。我的错误在哪里?RelativeLayout中的ScrollView不起作用

<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,也改变了滚动高度WRAP_CONTENT。也没有父母的布局。像weight attr一样,你应该使用LinearLayout作为父Layout的父代 –

+0

的线性布局?如果是这样,你设定的weightSum是多少? –

+0

只在这个滚动视图上设置监听器像这样 [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> 
相关问题