i have in my android main.xml file as the following..
when i run it is showing some exception but in main.xml in graphical view it is not showing any error..
follwing is my code inside Linearlayout
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName"/>
<EditText android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=""/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</ScrollView>
ScrollView should have ONLY ONE child.
ScrollView should have ONLY ONE child. in ur example u have placed 2 linear layouts inside scrollview which is causing error..
place the 2 linear layouts inside 1 linear layout and place the whole thing in scrollview. it will work..
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/UserNameText"/>
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/UserNameText"/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/UserNameText"/>
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/UserNameText"/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
ScrollViews can only contain a single child view. Wrap your two LinearLayouts in another LinearLayout.
You also have both linear layouts height set to match_parent. This won't work in a scrollview. They should both be set to wrap_content
try this xml for your problem
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName"/>
<EditText android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=""/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Thanks for more detail click this link Can we use a ScrollView inside a LinearLayout?
Scroll View can have only One Direct child..
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="UserName" />
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/login_button"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="login" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:layout_width="60dp"
android:layout_height="30dp"
android:text="#string/login_btn" />
</LinearLayout>
</LinearLayout> </ScrollView>
ScrollView should have only one child.
Related
The following is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:layout_gravity="top"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:layout_weight="0.5"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:layout_marginLeft="50sp"
android:layout_marginBottom="5sp"
android:textSize="15sp"
android:textColor="#000000" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:src="#drawable/picframe" android:contentDescription="TODO"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="0.5"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
Basically I have 3 linear layouts
the first one is the size of the whole screen
the other two are inside the first and split the screen into two
the right hand layout displays a bitmap which works fine
The left hand layout displays a notes box
this all works fine but I want to make the left side scrollable so if you enter notes more than the height of the screen you can keep going and scroll down to see the rest
problem is it all works fine until I add the scrollview as above
the notes editbox and label disappear and cant be seen
If I remove the scrollview they come back
Any ideas where im going wrong?
As always any help appreciated
Mark
These are the changes you need to do in your xml
i.e. removing background color from scrollview and shifting linear layout background to scrollview and removing layout weight from linear layout and setting width as match_parent
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="0.5"
android:baselineAligned="false"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="0.5"
android:background="#ffffff"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginLeft="50sp"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:textColor="#000000"
android:textSize="15sp" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff"
android:ems="10"
android:textColor="#000000" >
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:contentDescription="TODO"
android:src="#drawable/image" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#FFFFFF"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
In you case equal weight is needed for child ScrollView and LinearLayout and set Scoll data to center of ScrollView :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F2F2"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Notes:"
android:textSize="15sp"
android:textColor="#000000"
android:layout_marginTop="5dp"/>
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:background="#ffffff"
android:layout_marginTop="5dp">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/picframe"
android:contentDescription="TODO"
android:layout_marginTop="5dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="1"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
Give this one a try, you don't need to give 0dp to your child LinearLayout.
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:orientation="vertical" >
I am trying to show four direct children on a Relative Layout where first one is a EdiText (in 'gone' visibility) and second one is LinearLayout with a TextView and ImageView and third is a ListView and fourth is another LinearLayout.
ListView gets over all children. I am posting below the code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollview"
android:background="#drawable/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.antoinecampbell.gcmdemo.GcmActivity$PlaceholderFragment">
<EditText
android:id="#+id/recepient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:imeOptions="actionSend"
android:inputType="phone"
android:visibility="invisible">
<requestFocus />
</EditText>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/recepient" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:text="Preview"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"/>
<ImageView android:id="#+id/imageShow"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/abs__ic_go"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
</LinearLayout>
<ListView android:id="#+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
/>
<LinearLayout
android:id="#+id/bottomview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#+id/listMessages"
android:layout_alignParentBottom="true"
android:visibility="gone"
android:background="#FFFFFF">
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/name_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:layout_weight="1"
android:hint="#string/enter_message_text"
android:imeOptions="actionSend"
android:inputType="text"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<LinearLayout android:layout_width="wrap_content"
android:id="#+id/frameView"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<fragment
android:id="#+id/emojicons"
android:layout_width="match_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment"/>
</LinearLayout>
<ImageButton
android:id="#+id/send_message_button"
android:background="#drawable/angry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:visibility="visible"/>
</LinearLayout>
</RelativeLayout>
Now I tried using LinearLayout with scrollview inside it, it's now not scrolling the listview
<?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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/recepient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:imeOptions="actionSend"
android:inputType="phone"
android:visibility="invisible">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:text="Preview"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone"/>
<ImageView android:id="#+id/imageShow"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/abs__ic_go"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<ListView android:id="#+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LinearLayout1"
android:cacheColorHint="#00000000"
android:divider="#00000000"
android:listSelector="#00000000"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottomview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_below="#+id/listMessages"
android:layout_alignParentBottom="true"
android:visibility="visible"
android:background="#FFFFFF">
<com.rockerhieu.emojicon.EmojiconEditText
android:id="#+id/name_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_small"
android:layout_weight="1"
android:hint="#string/enter_message_text"
android:imeOptions="actionSend"
android:inputType="text"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<LinearLayout android:layout_width="wrap_content"
android:id="#+id/frameView"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<fragment
android:id="#+id/emojicons"
android:layout_width="match_parent"
android:layout_height="220dp"
class="com.rockerhieu.emojicon.EmojiconsFragment"/>
</LinearLayout>
<ImageButton
android:id="#+id/send_message_button"
android:background="#drawable/angry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:visibility="visible"/>
</LinearLayout>
</LinearLayout>
The ListView will go over other elements because you've not given it any relative positions. In a relative layout, every element will be default appear at (0,0) (ie the top left corner of the view) unless it's given a layout_below, layout_alignBottom etc parameter to determine where it's drawn.
So in this case, you 'resumably want the ListView to have android:layout_below="#id/LinearLayout1 and the bottomview similarly android:layout_below="#id/listMessages.
Here is the xml as per your requirement.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center" >
<EditText
android:id="#+id/edNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Number"
android:inputType="phone"
android:visibility="gone" />
<LinearLayout
android:id="#+id/llLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/edNumber"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="linear layout text" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
</LinearLayout>
<ListView
android:id="#+id/lvList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/llBottom"
android:layout_below="#id/llLayout" >
</ListView>
<LinearLayout
android:id="#+id/llBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ababab"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Bottom Bar text" />
</LinearLayout>
</RelativeLayout>
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
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>
i have a layout made in xml for an android app. The last textview it is not shown. why? what can i do? i try setting the linearlayout with height : fill_parent, wrap_content and match_parent:
this is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/sfondo">
<LinearLayout android:id="#+id/linearLayout2"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_height="fill_parent" android:weightSum="1"
android:layout_width="fill_parent" android:orientation="horizontal">
<ImageButton android:id="#+id/back1" android:src="#drawable/back"
android:background="#null" android:layout_marginTop="25dip"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageButton>
<ImageView android:layout_height="wrap_content" android:id="#+id/logoTC"
android:src="#drawable/trovachiavi_contatti" android:layout_width="wrap_content"
android:layout_marginTop="20dp">
</ImageView>
<ImageButton android:id="#+id/infoButton"
android:background="#null" android:layout_height="wrap_content"
android:layout_marginTop="10dip" android:src="#drawable/info_mini"
android:layout_width="wrap_content"></ImageButton>
</LinearLayout>
</LinearLayout>
<LinearLayout android:layout_width="match_parent"
android:layout_height="fill_parent" android:id="#+id/layoutGif1"
android:orientation="vertical">
<spazio.digitale.com.GIFView
android:layout_gravity="center" android:layout_width="wrap_content"
android:layout_height="220dp" android:id="#+id/GIFMulti"
android:layout_marginLeft="40dp"></spazio.digitale.com.GIFView>
<TextView android:layout_height="wrap_content" android:id="#+id/testoAiuto"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content" android:gravity="center"
android:textColor="#android:color/black" android:layout_marginTop="-210dp"></TextView>
<ImageButton android:layout_gravity="center|bottom"
android:layout_width="wrap_content" android:layout_marginTop="25dp"
android:layout_height="wrap_content" android:background="#null"
android:id="#+id/avvia_cerca"></ImageButton>
<TextView android:layout_width="match_parent" android:id="#+id/testoRicercaMulti"
android:layout_height="wrap_content" android:textColor="#android:color/black"
android:textSize="14dp" android:gravity="center"
android:layout_gravity="center" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</TextView>
</LinearLayout>
It looks to me like your layout just isn't fitting. Wrap your views in a ScrollView, for example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/sfondo">
...
<ScrollView android:id="#+id/scroll" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="match_parent" android:id="#+id/testoRicercaMulti"
android:layout_height="wrap_content" android:textColor="#android:color/black"
android:textSize="14dp" android:gravity="center"
android:layout_gravity="center" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</TextView>
</ScrollView>
</LinearLayout>
Hope that helps!
your layout doesn't fit on your screen. wrap your main LinearLayout inside a ScrollView.
i have a problem with my scrollview...
my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ScrollView android:id="#+id/scrollView1" android:layout_width="wrap_content" android:layout_height="match_parent">
<RelativeLayout [...]>
<TextView [...]></TextView>
<Spinner [...]></Spinner>
<Button [...]></Button>
<ImageButton [...]></ImageButton>
<TextView [...]></TextView>
<TableLayout [...]>
<TableRow [...]>
<TextView [...]></TextView>
<TextView [...]></TextView>
<TextView [...]></TextView>
</TableRow>
<TableRow [...]>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<AutoCompleteTextView [...]></AutoCompleteTextView>
<Spinner [...]></Spinner>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
When i try to scroll in my App it wont work... what did i do wrong?
i deleted the properties from the elements. if you need them to solve the problem i can add them.
i did it to get a better overview.
thanks,
prexx
Try adding the ScrollView as the parent. Swich place with LinearLayout.
And dont forget to add the following on your ScrollView instead of the LinearLayout:
xmlns:android="http://schemas.android.com/apk/res/android"
And layout_widht and layout_height of the ScrollView should be set to "fill_parent"
This is my code which uses ScrollView in a calendar I made, could help you:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="#+id/dayView" android:text="Day" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:id="#+id/weekView" android:text="Week" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
<Button android:text="Month" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false"/>
<Button android:id="#+id/eventsView" android:text="Events" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/prevMonth"
android:src="#drawable/calendar_left_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<Button
android:id="#+id/currentMonth"
android:layout_weight="0.6"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#drawable/calendar_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<ImageView
android:id="#+id/nextMonth"
android:src="#drawable/calendar_right_arrow_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
<LinearLayout
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="20dp" android:text="Week" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/monday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/tuesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/wednesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/thursday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/friday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/saturday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="#+id/sunday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ViewFlipper
android:id="#+id/flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<GridView
android:id="#+id/weeks2"
android:numColumns="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:scrollbars="none">
</GridView>
<GridView
android:id="#+id/calendar2"
android:numColumns="7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none">
</GridView>
</LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/create_event"
android:text="Create event"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try adding android:fillViewport="true" to your scrollView.
The height of your scrollView should probably be either match_parent or fill_parent aswell.
If the ScrollView content doesn't take up the whole space, it will behave as a normal layout, i.e. non-scrollable.
If you still need the ScrollView to fill the entire screen (but still not scroll since there is not enough content) you could do as Nicholas Magnussen mentioned and add android:fillViewport="true"
Please change to android:layout_width="wrap_content" android:layout_height="wrap_content"
to fill parent.
Thank you