Unable to scroll listview items - android

I have layout with few text boxes and checkboxes. Between them is listview. When I add three or more items I can't see them in listview, the listview does not have scroll bar.
This is my layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="163dp"
android:orientation="horizontal" >
<!-- -------------HERE IS MY LISTVIEW--------------- -->
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/linearLayoutGlavni"
android:layout_below="#+id/linearLayoutGlavni"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reklamacija dobavljaču" />
<CheckBox
android:id="#+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/checkBox"
android:text="Prenamjena robe" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Otpis robe" />
<CheckBox
android:id="#+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="111dp"
android:layout_toRightOf="#+id/checkBox3"
android:text="Upozorenje djelatniku" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Obuka djelatnika" />
<CheckBox
android:id="#+id/checkBox6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="64dp"
android:layout_toRightOf="#+id/checkBox5"
android:text="Održavanje" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.68" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Is there something missing inside layout code or this must be solved through code?

You should never put a listview in a scrollView, because Listview is autoScrollable when its size increases than the screen.
Please refer to this link. Makers of Listview component.
Here you can find the best approaches of How to use a listview properly
https://www.youtube.com/watch?v=wDBM6wVEO70

I could suggest you to put only the ListView in a ScrollView. I think it will work, because I already tried it. So please try with something like this
<ScrollView
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="163dp"
<ListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView" />
</ScrollView>

Related

ScrollView dos not work

Dear All experts I have problem with using scrollView anyone please help.. the Error is showing that the ScrollView is useless and also in other form of mine is shows the same , how can I solve this and how can I make my forms and activities been scroll ??
`
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</ScrollView>
`
You need a child container as LinearLayout, TableLayout or RelativeLayout in your ScrollView like this:
<ScrollView
... >
<LinearLayout
... >
<!-- Your views: TextView, LinearLayout, etc. -->
</LinearLayout>
</ScrollView>
According to the reference:
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll
You should put all the other fields in a single Layout.. Like linear layout,relative layout. Your whole code should look like this
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</LinearLayout>
</ScrollView>
"Scrollview can host only one direct child"
Put all your stuff in some Layout e.g LinearLayout

set adjustable listView between two hardcoded items

I want to set list view between two hardcoded items. I can't leave the height value blank in listView, cause it's disappear. I try with wrap/fill.. but all this things making my listView fill whole layout. Here is my code:
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/buton_style" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="90dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Do kasy" />
</RelativeLayout>
How would you solve this problem?
By default , all your Views will be placed at the top left corner in your RelativeLayout. So you will usually want to add layout_below or layout_top to your component.
For a more detail description for RelativeLayout, see this
Try this one
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_below="#+id/textView1" >
Use a LinearLayout as the outmost container, and setthis to the ListView:
layout_height="0px
layout_weight="1"
// try this way
<?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="wrap_content"
android:padding="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do kasy" />
</LinearLayout>
</LinearLayout>

How to change height of scrollview to not overlap linear layout in android?

I have this xml layout, but the problem is that, in the scroll view, the height of it is spanning the whole screen and overlapping the bottom linear layout (drawing on top of it). Is there a way so that, I can get the scroll view height going only up to the linear layout on the bottom? I want the bottom 2 buttons to be aligned to the bottom of the screen.
Thanks
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ActivityProfile" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="310dp"
android:background="#bdbdbd"
android:src="#drawable/no_avatar" />
<TextView
android:id="#+id/textview_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="" />
</LinearLayout>
<TextView
android:id="#+id/textview_fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="" />
<TextView
android:id="#+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="" />
<TextView
android:id="#+id/textview_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="" />
<TextView
android:id="#+id/textview_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="" />
<TextView
android:id="#+id/textview_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="" />
<TextView
android:id="#+id/textview_lastactive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_datejoined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_dateleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CloseActivity"
android:text="#+string/back" />
<Button
android:id="#+id/button_exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="GoToEditProfile"
android:text="#+string/edit" />
</LinearLayout>
</RelativeLayout>
Change it to LinearLayout and use layout_weight :
<?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:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="310dp"
android:background="#bdbdbd"
android:src="#drawable/no_avatar" />
<TextView
android:id="#+id/textview_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="" />
</LinearLayout>
<TextView
android:id="#+id/textview_fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="" />
<TextView
android:id="#+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="" />
<TextView
android:id="#+id/textview_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="" />
<TextView
android:id="#+id/textview_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="" />
<TextView
android:id="#+id/textview_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="" />
<TextView
android:id="#+id/textview_lastactive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_datejoined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_dateleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CloseActivity"
android:text="#+string/back" />
<Button
android:id="#+id/button_exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="GoToEditProfile"
android:text="#+string/edit" />
</LinearLayout>
</LinearLayout>
hope help you.
in your linear layout (at the bottom) add it to be situated below the scrollview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_below=""#+id/scrollView1" <-- this code
>
and also change the main base layout to linearlayout so it wont overlap
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ActivityProfile"
android:orientation='horizontal'
>
dont forget to change the tab at the very end
</LinearLayout>

Android - How to position 4 text views?

UPDATE: I've opened a new thread with my updated question here:
Android - How to display 4 text views with Icons?
Thank you for your answers, I'd really appreciate it if you could help me with my newer thread above.
I'm trying to display 4 text views at the bottom of the screen but I can't figure out how to that that. Every time I try to move one button it screws up the rest.
Here's what it currently looks like:
Here's my manuel marks as to where I want to position the buttons (Each line represents a text view item position):
Here's the current code, any pointers would be really great:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="124dp"
android:layout_toRightOf="#+id/ButtonRate"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignRight="#+id/ButtonWallpaper"
android:text="TextView" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="50dp"
android:layout_marginTop="137dp"
android:clickable="true"
android:onClick="setWallpaper"
android:text="#string/set_wallpaper"
android:textColor="#color/red" />
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/ButtonWallpaper"
android:layout_alignBottom="#+id/ButtonWallpaper"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:clickable="true"
android:onClick="rate"
android:text="#string/rate_button"
android:textColor="#color/red" />
I'm really stuck.
Thanks very much in advance,
Dvir
You need to put another relative layout after ViewPager for your textViews, and add android:layout_alignParentBottom="true" to that Layout like this:
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/ButtonRate"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignRight="#+id/ButtonWallpaper"
android:text="TextView" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="50dp"
android:clickable="true"
android:onClick="setWallpaper"
android:text="hello" />
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/ButtonWallpaper"
android:layout_alignBottom="#+id/ButtonWallpaper"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:clickable="true"
android:onClick="rate"
android:text="hello2" />
</RelativeLayout>
Also note that I've deleted android:layout_marginTop parameters, you can adjust it, if you wish
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
You can do something like that :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="394dp"
android:adjustViewBounds="true" >
</android.support.v4.view.ViewPager>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/ButtonRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="39dp"
android:text="ButtonRate" />
<TextView
android:id="#+id/ButtonWallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="60dp"
android:text="ButtonWallpaper" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignLeft="#+id/ButtonWallpaper"
android:layout_marginLeft="22dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/ButtonRate"
android:layout_centerVertical="true"
android:text="TextView" />
</RelativeLayout>

How to show labels next to spinners in a relativeLayout

I have the following RelativeLayout:
<RelativeLayout 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="horizontal" >
<RadioGroup
<!--stuff-->
</RadioGroup>
<Spinner
android:id="#+id/colour_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1" />
<TextView
android:id="#+id/colourLabel"
android:text="#string/label_colour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_toLeftOf="#+id/colour_spinner"/>
<Spinner
android:id="#+id/country_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/colour_spinner" />
<TextView
android:id="#+id/countryLabel"
android:text="#string/label_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/colour_spinner"
android:layout_toLeftOf="#+id/country_spinner"/>
<Spinner
android:id="#+id/stadium_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/country_spinner" />
<TextView
android:id="#+id/stadiumLabel"
android:text="#string/label_stadium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/country_spinner"
android:layout_toLeftOf="#+id/stadium_spinner"/>
Hopefully it's obvious what I'm trying to do here. Three spinners, each below the one before, and a label to the left of each, ideally all lined up neatly.
The result I'm getting at the moment is that only the spinners show on the screen, and I get no text labels at all. What am I doing wrong here? I suspect it's to do with my layout width/height settings?
Enclose each spinner and label inside a horizontal LinearLayout:
<RelativeLayout 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">
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- stuff -->
</RadioGroup>
<LinearLayout
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup"
android:orientation="horizontal" >
<TextView
android:id="#+id/colourLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_colour" />
<Spinner
android:id="#+id/colour_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner1"
android:orientation="horizontal" >
<TextView
android:id="#+id/countryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/label_country" />
<Spinner
android:id="#+id/country_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="#+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner2"
android:orientation="horizontal" >
<TextView
android:id="#+id/stadiumLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_stadium" />
<Spinner
android:id="#+id/stadium_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="50dip" >
</RadioGroup>
<TextView
android:id="#+id/colourLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:text="label_colour"
android:textColor="#android:color/white" />
<Spinner
android:id="#+id/colour_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_toRightOf="#+id/colourLabel" />
<TextView
android:id="#+id/countryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/colour_spinner"
android:text="label_country"
android:textColor="#android:color/white" />
<Spinner
android:id="#+id/country_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/colour_spinner"
android:layout_toRightOf="#+id/countryLabel" />
<TextView
android:id="#+id/stadiumLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/country_spinner"
android:text="label_stadium" />
<Spinner
android:id="#+id/stadium_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/country_spinner"
android:layout_toRightOf="#+id/stadiumLabel" />
</RelativeLayout>

Categories

Resources