2014-10-06 4 views
0

У меня есть вид прокрутки, содержащий один дочерний макет (линейный макет), и этот ребенок содержит относительный макет и линейный макет. Относительная компоновка и линейная компоновка разделяют половину экрана. Линейный макет имеет кнопки, добавленные к нему динамически.ScrollView не прокручивает переполненный макет

Теперь проблема возникает, поскольку прокрутка не прокручивает кнопки, пока она прокручивает относительный макет и линейную компоновку.

<ScrollView> 
<LinearLayout> 

    <RelativeLayout>  
    </RelativeLayout> 

    <LinearLayout> 
          ->Dynamically adding buttons here 
    </LinearLayout> 

</LinearLayout> 
</ScrollView> 

Я хочу, чтобы эти кнопки прокрутки с Scrollview

Для справки мой XML-код: -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/whitecolor" 
android:orientation="vertical" 
> 

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 

<RelativeLayout 
    android: 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
<View 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/bluecolor" 
    /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/stauslinearlayout" 
    android:layout_marginBottom="8dp" 
    android:padding="5dp" 
    android:gravity="center" 
    android:textColor="@color/whitecolor" 
    android:text="@string/app_name" 
    /> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:background="@color/bluecolor" 
    > 
<EditText 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="@drawable/edit_text_custom" 
    android:singleLine="true" 
    android:hint="@string/status" 
    android:textColor="#000" 
    android:textColorHint="#5222" 
    android:padding="7dp" 
    android:maxLength="50" 
    android:cursorVisible="true" 
    android:layout_marginBottom="10dp" 
    android:layout_marginLeft="10dp" 
    android:drawableLeft="@android:drawable/ic_input_add" 
    android:ems="10" 
    /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="right|center_horizontal" 
    android:gravity="center" 
    android:layout_weight="0" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="10dp" 
    android:padding="5dp" 
    android:text="@string/statusnumber" 
    android:background="@drawable/edit_text_custom" 
    /> 
</LinearLayout> 
</RelativeLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/whitecolor" 
    android:text="abcdfrg" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
    <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
    <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
     <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
     <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    />    
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

ответ

0

AFAIK, если вы хотите, чтобы разделить экран и тот же два размера, вам нужно взять еще один scrollView в виде снизу, как показано ниже ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:orientation="vertical" > 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/darker_gray" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/stauslinearlayout" 
        android:layout_marginBottom="8dp" 
        android:gravity="center" 
        android:padding="5dp" 
        android:text="@string/app_name" 
        android:textColor="@android:color/white" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:background="@android:color/darker_gray" 
        android:orientation="horizontal" > 

        <EditText 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="10dp" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:cursorVisible="true" 
         android:drawableLeft="@android:drawable/ic_input_add" 
         android:ems="10" 
         android:hint="status" 
         android:maxLength="50" 
         android:padding="7dp" 
         android:singleLine="true" 
         android:textColor="#000" 
         android:textColorHint="#5222" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="right|center_horizontal" 
         android:layout_marginBottom="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_weight="0" 
         android:gravity="center" 
         android:padding="5dp" 
         android:text="statusnumber" /> 
       </LinearLayout> 
      </RelativeLayout> 

      <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" > 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" > 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:background="@android:color/white" 
         android:text="abcdfrg" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 
       </LinearLayout> 
      </ScrollView> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

, и если вы не хотите брать другой scrollView, тогда вы должны предоставить wrap_contant до нижнего линейного макета.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:orientation="vertical" > 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/darker_gray" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/stauslinearlayout" 
        android:layout_marginBottom="8dp" 
        android:gravity="center" 
        android:padding="5dp" 
        android:text="@string/app_name" 
        android:textColor="@android:color/white" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:background="@android:color/darker_gray" 
        android:orientation="horizontal" > 

        <EditText 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="10dp" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:cursorVisible="true" 
         android:drawableLeft="@android:drawable/ic_input_add" 
         android:ems="10" 
         android:hint="status" 
         android:maxLength="50" 
         android:padding="7dp" 
         android:singleLine="true" 
         android:textColor="#000" 
         android:textColorHint="#5222" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="right|center_horizontal" 
         android:layout_marginBottom="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_weight="0" 
         android:gravity="center" 
         android:padding="5dp" 
         android:text="statusnumber" /> 
       </LinearLayout> 
      </RelativeLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/white" 
        android:text="abcdfrg" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

выбор подходит к вашим требованиям.

если проблема еще, то плз спросить ... :-)

+0

я не могу использовать первый метод, потому что я хочу, и нижестоящего макета для перемещения с одного Scrollview. Второй метод дает то же поведение, что и моя проблема. Однако мне удалось это сделать, динамически устанавливая высоту первого ребенка на высоту экрана/2, а затем добавляя кнопки для динамического прокрутки. Большое спасибо! – Aviverma

+0

@Aviverma, хорошо приветствуется. – Rumit

Смежные вопросы