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.
Related
I'm kind of new in Android App develop, there is my problem, I created a scrollview, inside scrollview I have LinearLayout. The problem is in the LinearLayout I cannot put the textview beside to the ImageView, really stuck here.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.ItemDetail">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textStyle="bold"
android:textSize="20dp"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_alignParentLeft="true"
android:layout_margin="8dp"
android:layout_height="80dp" />
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_seller"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView_seller"
android:layout_toRightOf="#+id/imageView_seller"
android:layout_gravity="center_horizontal"
android:textSize="20dp"
android:text="Seller INFO"/>
</LinearLayout>
</ScrollView>
This is what happened
This XML Code might help you...
I have set imageView_seller at leftside of tv_sellerInfo
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center_vertical"
android:layout_margin="8dp"/>
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Seller INFO"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
This happens because the orientation of your LinearLayout is vertical (one view below the other), try to change to horizontal or change of LinearLayout to RelativeLayout and add the constraints that you want.
add a linearlayout where you want to put textview right of image view. set the orientation of this linearlayout is hrizontal then put imageview and then textview in this linearlayout
do this -
android:orientation="horizontal"
like this-
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_item_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:orientation="horizontal"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:fillViewport="true"
tools:context="com.example.daniw.traekle.ItemDetail">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/tv_bookTitle"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="Title"
android:textStyle="bold"
android:textSize="20dp"/>
<TextView
android:id="#+id/tv_ISBN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="ISBN"/>
<ImageView
android:id="#+id/imageView_book"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
android:layout_marginBottom="5dp"
android:paddingBottom="50dp"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="3dp"
android:scaleType="fitXY"/>
<TextView
android:id="#+id/tv_bookPrice"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:text="$0.00"
android:textSize="30dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_bookInfo"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginBottom="5dp"
android:text="This is bookInfo"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<ImageView
android:id="#+id/imageView_seller"
android:layout_width="80dp"
android:layout_alignParentLeft="true"
android:layout_margin="8dp"
android:layout_height="80dp" />
<TextView
android:id="#+id/tv_sellerInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView_seller"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView_seller"
android:layout_toRightOf="#+id/imageView_seller"
android:layout_gravity="center_horizontal"
android:textSize="20dp"
android:text="Seller INFO"/>
</LinearLayout>
</ScrollView>
I have a listview which contains a linearlayout. I am trying to get the linearlayout to the center of the screen(horizontally) but it doesn't work.
How it looks -
Portrait -
Landscape -
I want the linearlayout(which has the text "text" and the two images) to come to the center of the screen(horizontally) in both the orientations.
I've tried using layout_gravity on the linearlayout but it doesn't work.
Here's my code -
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
Each listview item -
<?xml version="1.0" encoding="utf-8"?>
<!-- I want this layout centered. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Please help.
EDIT: Neither gravity="center" works on the listview, nor does layout_gravity="center" on the linearlayout.
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
See here for explanation : https://stackoverflow.com/a/3482757/4706693
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
I have a layout as below
<LinearLayout>
<RelativeLayout>
</RelativeLayout>
<ScrollView>
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
this is to divide the screen into half showing graph at one half of the screen and the report at the other half which alone i wish to be scrollable.
UPDATE
Please find the xml as below
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888" />
<LinearLayout
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_marginBottom="10sp"
android:orientation="vertical">
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888"
android:orientation="vertical" />
<LinearLayout
android:id=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
android:orientation="horizontal">
<RelativeLayout
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:id="#+id/course_status"
android:layout_alignParentLeft="true"
android:textColor="#000000"
android:textSize="14sp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<edu.apollogrp.android.widget.ProgressCircle
android:id=""
android:layout_width="170dp"
android:layout_height="170dp"
android:indeterminateOnly="false"
android:layout_centerInParent="true"
android:progressDrawable=""
android:layout_marginTop="50dp"
/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight=""
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:addStatesFromChildren="false"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#
android:textColor="#color/grades_green"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="#
android:textColor=""
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> </TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:layout_marginLeft="40dp" >
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/grades_green"
android:textSize="12sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="9sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:background="#888888"
android:orientation="horizontal" />
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:fillViewport="false"
>
<LinearLayout
android:id="#
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
but the whole layout is scrollable now :(
Is there any way i can make only half the screen scrollable?
PS: android:fillViewport is set to false
UPDATE
I found out why the scroll is not working. it was because the scroll was inside a pull to refresh list view. :(
Looking for a work around for that now
Use layout_weight, here is sample code
<LinearLayout>
<RelativeLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
try to put the layout_weight attribute to divide the screen.
<LinearLayout>
<RelativeLayout android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
you can try this:
<?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:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parentt"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:layout_weight="1">
////// Your left side layout content /////////
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:orientation="vertical"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
<TextView
android:id=""
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
The scroll view was not working because it was inside a list view that implements the pull to refresh.. Hence the layout changes dont effect.
Sorry everyone, thanks a bunch for the help.
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.
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