3

I have a problem in my xml, the ScrollView does not work when my RelativeLayout is wrap_content, but if I have a larger screen than the fixed height works correctly, but if I have a larger fixed height than screen the works correctly, but I need to be wrap_content, because I have a listview that is populated gradually as client wants, follows the xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
android:orientation="horizontal" 
android:baselineAligned="false">

<LinearLayout 
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#fff">
    </LinearLayout>

        <ScrollView 
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="45"
            android:fillViewport="true"
            android:scrollbars="vertical">

            <RelativeLayout 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent"
                android:padding="2dp"
                android:background="@drawable/borda"
                android:orientation="vertical">
                    <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="top|center_horizontal"
                        android:id="@+id/lb_cabec"
                        android:text="@string/str_cabec" />

                    <TextView
                        android:id="@+id/lb_pessoa_status"
                        android:paddingTop="4dp"
                        android:paddingBottom="15dp"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="bottom"
                        android:textStyle="bold"
                        android:text="@string/pessoas_lb_mesa_cartao" 
                        android:layout_below="@+id/lb_cabec"/>

                     <RelativeLayout 
                        android:layout_height="wrap_content" 
                        android:layout_width="fill_parent"
                        android:padding="2dp"
                        android:background="@drawable/borda"
                        android:id="@+id/relative_prod"
                        android:layout_below="@+id/lb_pessoa_status">

                        <TextView
                            android:layout_width="fill_parent"
                            android:id="@+id/lb_prodMistAdd_cabec_prod"
                            android:layout_height="wrap_content"
                            android:background="#000"
                            android:textColor="#fff"
                            android:gravity="center_horizontal"
                            android:text="@string/prodMistAdd_str_prod" />

                        <ListView
                            android:id="@+id/mListProdMistAdd_prod"
                            android:layout_width="fill_parent"
                            android:layout_marginBottom="10dp"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/lb_prodMistAdd_cabec_prod" />

                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="35dp"
                            android:layout_below="@+id/mListProdMistAdd_prod"
                            android:layout_centerHorizontal="true"
                            android:gravity="center_horizontal"
                            android:id="@+id/bt_prodMistAdd_addProd"
                            android:text="@string/prodMistAdd_bt_prod" />


                    </RelativeLayout>

                     <LinearLayout 
                        android:layout_height="10dp" 
                        android:layout_width="fill_parent"
                        android:id="@+id/lb_espaco_1"
                        android:layout_below="@+id/relative_prod"
                        android:orientation="vertical">

                     </LinearLayout>

                     <RelativeLayout
                        android:layout_height="wrap_content" 
                        android:layout_width="fill_parent"
                        android:padding="2dp"
                        android:background="@drawable/borda"
                        android:id="@+id/relative_quant"
                        android:layout_below="@+id/lb_espaco_1">

                        <TextView
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:id="@+id/lb_prodMistAdd_cabec_quant"
                            android:background="#000"
                            android:textColor="#fff"
                            android:gravity="center_horizontal"
                            android:text="@string/prodMistAdd_str_quant" />

                        <LinearLayout 
                            android:layout_height="5dp" 
                            android:id="@+id/tab_espaco_2"
                            android:layout_below="@+id/lb_prodMistAdd_cabec_quant"
                            android:layout_width="fill_parent"
                            android:orientation="vertical"
                            android:background="#fff">
                        </LinearLayout>


                        <LinearLayout 
                            android:layout_height="wrap_content" 
                            android:layout_width="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:layout_below="@+id/tab_espaco_2"
                            android:orientation="horizontal">

                            <EditText
                                android:id="@+id/tb_prodMistAdd_quantidade"
                                android:layout_width="60dp"
                                android:layout_height="wrap_content"
                                android:editable="false"
                                android:gravity="center_vertical|right"
                                android:ems="10"
                                android:inputType="textPersonName" />

                            <Button
                                android:layout_width="40dp"
                                android:layout_height="35dp"
                                android:gravity="center_horizontal"
                                android:id="@+id/bt_prodMistAdd_mais"
                                android:text="@string/prodMistAdd_bt_mais" />


                            <Button
                                android:layout_width="40dp"
                                android:layout_height="35dp"
                                android:gravity="center_horizontal"
                                android:id="@+id/bt_prodMistAdd_menos"
                                android:text="@string/prodMistAdd_bt_menos" />

                        </LinearLayout>

                     </RelativeLayout>

                     <LinearLayout 
                        android:layout_height="10dp" 
                        android:layout_width="fill_parent"
                        android:id="@+id/lb_espaco_2"
                        android:orientation="vertical"
                        android:layout_below="@+id/relative_quant">

                     </LinearLayout>

                     <RelativeLayout 
                        android:layout_height="wrap_content" 
                        android:layout_width="fill_parent"
                        android:padding="2dp"
                        android:background="@drawable/borda"
                        android:id="@+id/relative_obs"
                        android:layout_below="@+id/lb_espaco_2">

                        <TextView
                            android:layout_width="fill_parent"
                            android:id="@+id/lb_prodMistAdd_cabec_obs"
                            android:layout_height="wrap_content"
                            android:background="#000"
                            android:textColor="#fff"
                            android:gravity="center_horizontal"
                            android:text="@string/prodMistAdd_str_obs" />

                        <LinearLayout 
                            android:layout_height="5dp" 
                            android:id="@+id/tab_espaco_3"
                            android:layout_below="@+id/lb_prodMistAdd_cabec_obs"
                            android:layout_width="fill_parent"
                            android:orientation="vertical"
                            android:background="#fff">
                        </LinearLayout>


                        <ListView
                            android:id="@+id/mListProdMistAdd_obs"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content"
                            android:scrollbars="none"
                            android:layout_below="@+id/tab_espaco_3" />

                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="35dp"
                            android:layout_below="@+id/mListProdMistAdd_obs"
                            android:layout_centerHorizontal="true"
                            android:gravity="center_horizontal"
                            android:id="@+id/bt_log_voltar"
                            android:text="@string/prodMistAdd_bt_obs" />


                </RelativeLayout>       
            </RelativeLayout>       
        </ScrollView>

    <LinearLayout 
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1">

    </LinearLayout>


  </LinearLayout>

My listview are configured to not scroll, through code

1 Answers1

0

try do define ScrollView layout_width and layout_height as match_parent, without layout_weight

by the way, you should not mix ScrollView with ListView since both have his own scroll. I suggest to split it like:

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

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

        (...)
    </ScrollView>

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

        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

    </LinearLayout>
PedroHawk
  • 622
  • 5
  • 19
  • But i need a margin, match_parent occupy all the space in the horizontal orientation, and notwithstanding don't work – Gabriel Santos Jun 06 '14 at 12:47
  • in this case the listview not disappears when stay big? – Gabriel Santos Jun 06 '14 at 13:01
  • in this case you have 2 separated things: -all stuff inside scrollView have his own scroll (if needed), AND everthing inside listView. -ListView will disappear only if have no data inside ofcourse (wrap content) – PedroHawk Jun 06 '14 at 13:07
  • I do not wish it had more of a scroll, wish that functioned as a kind of gridview, a simple list, it not need a scroll it, just scroll the page. is it possible? or i try other way? – Gabriel Santos Jun 06 '14 at 13:16
  • Understand that ScrollView have is own scroll properties and listView others. Thats why you shouldnt mix it up. – PedroHawk Jun 06 '14 at 13:38
  • The porpose of listView is to load data and become scrollable on that determinated space; ScrollView its all about scrolling whats inside it (can be full page) – PedroHawk Jun 06 '14 at 13:45