Scrollable list of buttons within SliderDrawer - android

No luck after a few days of researching this one. Should be simple, but I'm just not seeing it.
There is an activity page, which has a SliderDrawer. SlidingDrawer icon sits at the bottom, on click or swipe slides open drawer correctly with list of buttons. That all works fine. The problem I'm having is that to accomodate different screensizes and orientations, and the likely addition of additional buttons, I need the contents of that SlidingDrawer to be scrollable. Layout is below. I have tried wrapping the LinearLayout that holds the buttons in a ScrollView without success.
Suggestions?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/frontpagetitlewrapper"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="blah"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center"
android:layout_alignParentTop="true"
/>
<TextView
android:id="#+id/mid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="and"
android:textColor="#000000"
android:layout_below="#+id/top"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center"
/>
<TextView
android:id="#+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="blather"
android:textColor="#000000"
android:layout_below="#+id/mid"
android:textSize="18sp"
android:textStyle="bold"
android:gravity="center"
/>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:id="#+id/frameLayout"
android:layout_alignParentBottom="true">
<SlidingDrawer android:layout_height="wrap_content"
android:handle="#+id/handle"
android:content="#+id/content"
android:id="#+id/slide"
android:orientation="vertical"
android:layout_width="fill_parent"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/handle"
android:src="#drawable/opendrawer">
</ImageView>
<ScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/content"
android:orientation="vertical">
<Button android:text="a" android:id="#+id/btnA" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
<Button android:text="b" android:id="#+id/btnB" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
<Button android:text="c" android:id="#+id/btnC" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
<Button android:text="d" android:id="#+id/btnD" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
<Button android:text="e" android:id="#+id/btnE" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
<Button android:text="f" android:id="#+id/btnF" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textStyle="bold" android:textSize="20dip"></Button>
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</FrameLayout>
</RelativeLayout>

I think your problem is that you've tagged the nested LinearLayout with instruction
android:id="#id/content"
so that's the component the SlidingDrawer is using for the content.
Try tagging the ScrollView instead.

<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer android:layout_width="wrap_content"
android:id="#+id/SlidingDrawer" android:handle="#+id/slideHandleButton"
android:content="#+id/contentLayout" android:padding="10dip"
android:layout_height="250dip">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/slideHandleButton"
android:background="#drawable/closearrow"></Button>
<LinearLayout android:layout_width="wrap_content"
android:id="#+id/contentLayout" android:orientation="vertical"
android:gravity="center|top" android:padding="10dip"
android:background="#C0C0C0" android:layout_height="wrap_content">
<Button android:id="#+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="#+id/Button02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="#+id/Button03" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Content"></Button>
</LinearLayout>
</SlidingDrawer>

Related

Nesting RelativeLayouts within LinearLayout

I am trying to achieve the following layout in Android with the main heading at the top and three subheadings spaced equally apart below, with some buttons below that:
I was able to accomplish this with the following XML, but I feel like I am not using the RelativeLayout and LinearLayout properly:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cfff"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="Title"
android:textSize="80sp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight=".5">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_number1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption1"
android:text="1"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_number2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption2"
android:text="10"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_sets"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption3"
android:text="3"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
</LinearLayout>
<!-- Button1 -->
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button1"
android:textSize="20sp"/>
<!-- Button2 -->
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Button2"
android:textSize="20sp" />
</LinearLayout>
I'm focusing somewhat on the Subheading portion, although any suggestions on the overall layout would be welcome. So I used 3 different RelativeLayouts to put the "Subheading" captions with their respective numbers, and nested those within a horizontal LinearLayout to get them spaced next to each other horizontally.
This seems to be creating a bit of a problem, since Android Studio is complaining that my use of layout_weight within nested layouts is bad for performance. When I get rid of the layout_weight however, everything falls apart and I only see the "Title" and one subheading. I'm also wondering whether I could have accomplished this more elegantly with just one RelativeLayout and no nesting, but I can't see how to code something like this without the use of a LinearLayout.
Thanks in advance for any suggestions!
Yes,you can accomplish this more elegantly with just one RelativeLayout and no nesting
I hope this is what you are looking for
<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:background="#cfff"
tools:context=".MainActivity">
<TextView
android:id="#+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Title"
android:textSize="80sp" />
<TextView
android:id="#+id/text_caption1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/text_number1"
android:text="Subheading"
android:textSize="18sp" />
<TextView
android:id="#+id/text_number1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="left"
android:text="1"
android:textSize="80sp" />
<TextView
android:id="#+id/text_caption2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/text_number2"
android:gravity="center"
android:text="Subheading"
android:textSize="18sp" />
<TextView
android:id="#+id/text_number2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="2"
android:textSize="80sp" />
<TextView
android:id="#+id/text_caption3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/text_number3"
android:gravity="right"
android:text="Subheading"
android:textSize="18sp" />
<TextView
android:id="#+id/text_number3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="right"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:text="Button1"
android:textSize="20sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button2"
android:textSize="20sp" />
</RelativeLayout>
try this one...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="5"
android:text="TITLE"
android:layout_gravity="center"
android:gravity="center"
android:textSize="45sp"
android:id="#+id/textView64" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:weightSum="10">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="3.25"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subheading"
android:id="#+id/textView66" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="50sp"
android:id="#+id/textView67" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="3.5"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SubHeading"
android:id="#+id/textView68" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="50sp"
android:id="#+id/textView69" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="3.25"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SubHeading"
android:id="#+id/textView70" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="50sp"
android:id="#+id/textView71" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.8"
android:text="New Button"
android:id="#+id/button"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="0.8"
android:text="New Button"
android:id="#+id/button1"
/>
Change android:weightSum and android:layout_weight acoording to your required ratio...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cfff"
android:orientation="vertical"
tools:context=".MainActivity"
android:weightSum="4">
<TextView
android:id="#+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1.5"
android:text="Title"
android:textSize="80sp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1.5"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_number1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption1"
android:text="1"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_number2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption2"
android:text="10"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/text_caption3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subheading"
android:gravity="center"
android:textSize="18sp"/>
<TextView
android:id="#+id/text_sets"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text_caption3"
android:text="3"
android:layout_weight="1"
android:textSize="80sp"
android:gravity="center"/>
</RelativeLayout>
</LinearLayout>
<!-- Button1 -->
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button1"
android:layout_weight=".5"
android:textSize="20sp"/>
<!-- Button2 -->
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="Button2"
android:textSize="20sp" />
</LinearLayout>

align buttons with texts to the left side xml android

In this code I need align the buttons a Textview to the left, I try everythnin , with relative layout, gravity etcc....
I dont now why this align still togehter to the center in horizontal line, I need to the left side!
<?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="#color/dark_background"
android:orientation="vertical"
android:gravity="left" >
<ScrollView android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:gravity="left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dip"
>
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_page_intro"
android:padding="2dip"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="4dip"
android:layout_gravity="left"
>
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section1"
android:drawableTop="#drawable/help_image1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section1"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button android:id="#+id/help_button2"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section2"
android:drawableTop="#drawable/help_image2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section2"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentLeft="true">
<Button android:id="#+id/help_button3"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section3"
android:drawableTop="#drawable/help_image3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section3"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left" >
<Button android:id="#+id/help_button4"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section4"
android:drawableTop="#drawable/help_image4"/>
<TextView
android:layout_width="wrap_content"
android:gravity="left"
android:layout_height="wrap_content"
android:text="#string/help_text_section4"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
Sorry, not fully understanding. Did you want them lined up vertically? Then that would just be setting orientation to vertical in the linear layout. I looked at what this xml does right now. It appears to be button which is half the screen and textview with is the other half. Could you explain a little more what you want to see?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:onClick="onClickHelp"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/black"
android:padding="2dip"
android:layout_weight="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

How to make text scroll and keep other elements fixed to the bottom of the screen?

I'm trying to create the following display, where the text scrolls and the other elements are fixed to the bottom of the screen:
However, it is appearing as follows, where the text doesn't scroll and it's pushing the elements off the screen.:
This is the layout I'm using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ScrollView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="20dp"
android:layout_alignParentLeft="true" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:text="Don't Show Again"
android:layout_below="#+id/scroller" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:src="#drawable/stop"
android:paddingBottom="5dip"
android:paddingRight="5dip"
android:background="#drawable/common_button" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
What do I need to do to make the text scroll and the other elements fixed to the bottom of the screen?
Try replacing this xml code and apply images where you need
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5555"
android:gravity="center"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Terms and Conditions"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/txtTC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="20dp"
android:textSize="20sp" />
</ScrollView>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/scroller"
android:layout_gravity="center_vertical"
android:text="Don&apos;t Show Again" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/chkBox"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:id="#+id/imgCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingTop="0dip"
android:paddingBottom="5dip"
android:paddingRight="5dip" />
<TextView
android:id="#+id/txtCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_below="#id/imgCancel"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="OK"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
You should add the ScrollView Containing the TextView inside a Layout(Linear would do). I hope it helps

How to prevent layout moving?

I have one main layout in my quiz game and in it 3 more nested layout, one below another, vertical. In the top one I have a text view for the question, the middle one with four buttons vertically arranged. Now, when I have one line question everything is fine, but as soon as question goes to two line, my buttons move down one row. How to prevent this? I want everything below my question to be fixed, static, not to move.
<?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:background="#drawable/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="404dp"
android:orientation="vertical"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<TextView
android:id="#+id/tvPitanje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="#string/tvPitanje"
android:textSize="22sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bOdgovor1"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/buttons"
android:text="#string/bOdgovor1"
android:textSize="26sp" />
<Button
android:id="#+id/bOdgovor2"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/buttons"
android:text="#string/bOdgovor2"
android:textSize="26sp" />
<Button
android:id="#+id/bOdgovor3"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/buttons"
android:text="#string/bOdgovor3"
android:textSize="26sp" />
<Button
android:id="#+id/bOdgovor4"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#drawable/buttons"
android:text="#string/bOdgovor4"
android:textSize="26sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<Button
android:id="#+id/bIzlazIzKviza"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:background="#drawable/buttons"
android:text="#string/bIzlazKviz"
android:textSize="23sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/tvCountdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/tvCountdown"
android:textColor="#ff0000"
android:textSize="29sp" />
<TextView
android:id="#+id/tvSkor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="#string/tvSkor"
android:textSize="23sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:id="#+id/tvBrojPitanja"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="1"
android:textSize="32sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
A little later, but here we go, there are several solutions for this problem I will point out here two of them that probably are the most user friendly:
Use a scrollview for everything, IMHO this is the most user friendly solution.
Use scrollview just for text and buttons with a defined height, and put the below text and buttons static underneath, make use of a relative layout then.
Marquee text view
the first option I will put out here, with some layout refactoring included, the second one I wont recommend to use, put pretty simple to achieve if you have example one:
<?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:background="#android:color/background_light"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvPitanje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="long text that will automaticly scroll and make sure all content will be displayed right in the scrollview this is the best case scenario"
android:textSize="22sp"/>
<Button
android:id="#+id/bOdgovor1"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="one"
android:textSize="26sp"/>
<Button
android:id="#+id/bOdgovor2"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="two"
android:textSize="26sp"/>
<Button
android:id="#+id/bOdgovor3"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="three"
android:textSize="26sp"/>
<Button
android:id="#+id/bOdgovor4"
android:layout_width="260dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="four"
android:textSize="26sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:id="#+id/bIzlazIzKviza"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="left"
android:textSize="23sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/tvCountdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="next"
android:textColor="#ff0000"
android:textSize="29sp"/>
<TextView
android:id="#+id/tvSkor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="middle"
android:textSize="23sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:id="#+id/tvBrojPitanja"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="30dp"
android:text="right"
android:textSize="32sp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Marquee solution less nice
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit ="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"

Directly Nesting Linear Layouts only shows the first child view

I am trying to nest two Linear Layouts as direct children of another Linear Layout. Eventually the intention is for these two layouts to be nested within a ViewFlipper, so each of the two Linear Layouts will be flipped in and out of the screen.
The Layouts work fine until I nest the two Linear Layouts within a parent element, in which case only the first widget in the first child is displayed. So I have something like this:
<LinearLayout (parent)...
<LinearLayout (child1)...
<child1's Widgets... <---only the first widget here is being shown
<LinearLayout (child2)...
<child2's widgets...
I have no idea why this could be happening. Can anybody shed any light??
Full code:
<?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="#FFFFFF">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:layout_gravity="center"
android:gravity="center"
android:text="Hello, is this a great app?"
android:textColor="#000000"
android:layout_marginBottom="10dip"
android:layout_marginTop="8dip"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnYes"
android:text="Yes"
android:textSize="20sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="7dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"/>
<Button
android:id="#+id/btnNo"
android:text="No"
android:textSize="20sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="7dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"/>
</LinearLayout>
<!-- <ViewFlipper
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout <!-- ONLY THE CONTENT FROM HERE IS BEING SHOWN -->
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:text="Lat:"
android:textSize="16sp"
android:layout_weight="1"
android:layout_marginLeft="12dip"/>
<TextView
android:id="#+id/lblLat"
android:layout_width="0px"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_weight="3"
android:gravity="right"
android:layout_marginRight="12dip"/>
</LinearLayout> <!--NO MORE CONTENT Is SHOWN AFTER HERE -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:text="Lon:"
android:textSize="16sp"
android:layout_weight="1"
android:layout_marginLeft="12dip"/>
<TextView
android:id="#+id/lblLon"
android:layout_width="0px"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_weight="3"
android:gravity="right"
android:layout_marginRight="12dip"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:text="Number of satellites:"
android:textSize="16sp"
android:layout_weight="3"
android:layout_marginLeft="12dip"/>
<TextView
android:id="#+id/lblSats"
android:layout_width="0px"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_weight="1"
android:gravity="right"
android:layout_marginRight="12dip"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0px"
android:layout_height="wrap_content"
android:text="Signal To Noise:"
android:textSize="16sp"
android:layout_weight="3"
android:layout_marginTop="25dip"
android:layout_marginLeft="12dip"/>
<TextView
android:id="#+id/lblSNR"
android:layout_width="0px"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_weight="1"
android:gravity="right"
android:layout_marginTop="25dip"
android:layout_marginRight="12dip"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblAddresses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="16sp"
android:layout_marginLeft="12dip"
android:minLines="3"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lblAbout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stuff About App"
android:textSize="16sp"
android:layout_marginLeft="12dip"
android:minLines="3"/>
</LinearLayout>
<!-- </ViewFlipper> -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/btnLookup"
android:text="LookUp"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dip"
android:paddingTop="1dip"
android:paddingBottom="5dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dip"
android:layout_marginLeft="8dip" />
<Button
android:id="#+id/btnQuit"
android:text="Quit"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:padding="20dip"
android:paddingTop="1dip"
android:paddingBottom="5dip"
android:layout_marginBottom="8dip"
android:layout_marginRight="8dip" />
</RelativeLayout>
</LinearLayout>
Make sure to have on all your LinearLayout tags an android:orientation property.
<LinearLayout
..
android:orientation="vertical|horizontal">
...
</LinearLayout>
If you want to display the child components in vertical, you need to indicate it explicitly because by default it is set to horizontal.

Categories

Resources