Problem with View on change of device orientation - android

When I go to landscape mode, the bottom two buttons for my activity are not visible.The screen should have automatically converted into scrollable.Do I have to add something to my xml or manifest file?
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text in Hindi->"
/>
<TextView
style="#style/PassageStyle"
android:id="#+id/hindi"
android:textSize="30sp"
android:gravity="center"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Corresponding Text in English->"
/>
<TextView
style="#style/PassageStyle"
android:id="#+id/english"
android:textSize="30dip"
android:gravity="center"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/listen_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:text="#string/listen"
/>
<Button
android:id="#+id/slow_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slow"
android:layout_marginLeft="30dip"
android:layout_toRightOf="#id/listen_Button"
android:layout_alignTop="#id/listen_Button"
/>
<Button
android:id="#+id/voice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voice"
android:layout_alignLeft="#id/listen_Button"
android:layout_below="#id/listen_Button"
/>
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_below="#id/slow_button"
android:layout_alignLeft="#id/slow_button"
/>
</RelativeLayout>
</LinearLayout>

Where do you define your ScrollView?
Try it like this:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
... other stuff ...
</LinearLayout>
</ScrollView>

I have yet to use one, but this should work okay if you wrap the entire xml in a ScrollView.
http://developer.android.com/reference/android/widget/ScrollView.html

if you want that your screen scrollable , you should add a ScrollView as a root layout like this :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_heigth="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text in Hindi->"
/>
<TextView
style="#style/PassageStyle"
android:id="#+id/hindi"
android:textSize="30sp"
android:gravity="center"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Corresponding Text in English->"
/>
<TextView
style="#style/PassageStyle"
android:id="#+id/english"
android:textSize="30dip"
android:gravity="center"
/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/listen_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dip"
android:text="#string/listen"
/>
<Button
android:id="#+id/slow_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slow"
android:layout_marginLeft="30dip"
android:layout_toRightOf="#id/listen_Button"
android:layout_alignTop="#id/listen_Button"
/>
<Button
android:id="#+id/voice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voice"
android:layout_alignLeft="#id/listen_Button"
android:layout_below="#id/listen_Button"
/>
<Button
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_below="#id/slow_button"
android:layout_alignLeft="#id/slow_button"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>

Related

XML Layout overlap

I am trying to create a certain layout, that consists of 2 parts a scrollview and a "footer" at the bottom, but always on top of the scrollview. Everything inside the scrollview must be visible (by scrolling).
This is my current 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"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/banner" />
<TextView
android:layout_width="fill_parent"
android:paddingTop="1dp"
android:layout_height="3px"
android:background="#DADADA" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Start Connecting" />
<Button
android:id="#+id/button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_alignParentLeft="true"
android:text="First use" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Welcome to ADB Wireless!"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
But it gives an overlap on small screens & landscape mode. I would only like to have the 2 buttons to be inside the 'footer'. Thank you!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Next" />
<Button
android:id="#+id/button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Previous" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_layout" >
</ScrollView>
</RelativeLayout>

Align two image buttons horizontally in landscape layout Android with a text view under each one

I am making a chooser screen e.g gallery or take photo. I have made the portrait layout ok but struggling with landscape. I am trying to use DroidDraw. This is the kind of look I am going for as a sample (ignore the buttons), but the layout is deprecated.
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="#+id/widget65"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/widget66"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CAMERA"
android:layout_x="136dp"
android:layout_y="96dp" />
<Button
android:id="#+id/widget67"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GALLERY"
android:layout_x="272dp"
android:layout_y="95dp" />
<TextView
android:id="#+id/widget68"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose from Gallery"
android:layout_x="246dp"
android:layout_y="146dp" />
<TextView
android:id="#+id/widget69"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Picture"
android:layout_x="117dp"
android:layout_y="149dp" />
</AbsoluteLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget65"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="100dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/widget66"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="CAMERA" />
<TextView
android:id="#+id/widget68"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="Choose from Gallery" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="#+id/widget67"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="GALLERY" />
<TextView
android:id="#+id/widget69"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Take Picture" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Fill RelativeLayout parent with LinearLayout child

This seems simple but I've exhausted my Google search patience.
I have a RelativeLayout that has two sub LinearLayouts side-by-side and I want them both to vertically fill the parent, no matter the height of the two LinearLayouts. This is being used as a ListView row and the content under #id/item_left is generally shorter than the one on the right.
The background drawable doesn't fill the entire row.
Any ideas on making both sides fill?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:background="#drawable/item_left"
android:orientation="vertical">
<TextView android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_left_text"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/item_right_background"
android:layout_toRightOf="#id/item_left">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/item_right_text"
android:text="Row3" />
</LinearLayout>
</RelativeLayout>
try this code .... sorry but I changed the color to so the impact when you will change the text of first TextView
<?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="fill_parent"
android:background="#ffffffff" android:weightSum="1">
<LinearLayout android:id="#+id/item_left"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:paddingRight="2dp" android:paddingLeft="2dp"
android:background="#ff0000ff" android:orientation="vertical" >
<TextView android:id="#+id/time" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff555555"
android:text="sdfdsf s ada d a asd sad sad" />
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="match_parent" android:orientation="vertical"
android:background="#ffff0000"
android:layout_weight="1" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff555555"
android:text="Row1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff00ff00"
android:text="Row2" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#ff00ff00"
android:text="Row3" />
</LinearLayout>
</LinearLayout>
<?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:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="helloooooooooooooo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/layout1"
android:background="#0000FF"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row3" />
</LinearLayout>
</RelativeLayout>

No widget shows after scrollView in android

My design is like this: "Linearlayout start" "scrollview start" "scrollview end" "LinearLayout start" "LinearLayout end" "LinearLayout end". But second linear layout does not show in the screen.
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="fill_parent"
android:orientation="vertical"
>
<ScrollView
android:fillViewport="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/date" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/nasa" />
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/description" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button android:id="#+id/refresh" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/refresh">
</Button>
</LinearLayout>
</LinearLayout>
Thanks in advance
I found the solution. I need to add an extra attribute in ScrollView
<ScrollView android:layout_weight="1">
which prevent scroller to fill entire screen.
When your are using scrollView it needs to be as parent for the layout.
As per your code, follow the following code which was edited as per your requirement....
code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/date" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/nasa" />
<TextView
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/description" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button android:id="#+id/refresh" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/refresh">
</Button>
</LinearLayout>
</ScrollView>
Run the following code. It will execute...

android - xml. Having difficulty lining up the elements in the way I'd like

I'd like to center these phrases in my view. I can get "#+id/m_popcorn" to the center of the screen but, I cannot get"#+id/m_keyhole" and the other text views to line up beneath it. I would also like all five phrases to be centered in the screen, rather than having only "#+id/m_popcorn" centered. What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center" >
<ImageView
android:id="#+id/viola_desmond_pic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="#string/desc"
android:src="#drawable/viola_desmond" />
<TextView
android:id="#+id/list_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#AA000000"
android:contentDescription="#string/desc" >
</TextView>
<TextView
android:id="#+id/m_popcorn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="spilled popcorn" />
<TextView
android:id="#+id/m_keyhole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/m_popcorn"
android:layout_centerHorizontal="true"
android:text="keyhole" />
<TextView
android:id="#+id/m_pistol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/m_keyhole"
android:layout_centerHorizontal="true"
android:text="pistol" />
<TextView
android:id="#+id/m_cat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/m_pistol"
android:layout_centerHorizontal="true"
android:text="cat" />
<TextView
android:id="#+id/m_pen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/m_cat"
android:layout_centerHorizontal="true"
android:text="pen" />
</RelativeLayout>
Here is the layout file...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/viola_desmond_pic"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:contentDescription="testing"
android:src="#drawable/icon" />
<LinearLayout
android:id="#+id/ll_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/list_background"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#AA000000"
android:contentDescription="text description"
android:gravity="center_horizontal" >
</TextView>
<TextView
android:id="#+id/m_popcorn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="spilled popcorn" />
<TextView
android:id="#+id/m_keyhole"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="keyhole" />
<TextView
android:id="#+id/m_pistol"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="pistol" />
<TextView
android:id="#+id/m_cat"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="cat" />
<TextView
android:id="#+id/m_pen"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="pen" />
</LinearLayout>
</RelativeLayout>
you can use this code to have a list of textView in center of your layout, i am using a linear layout that fill the parent layout and set it's gravity to center, any child of this layout is in the center of it :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:scaleType="center">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:gravity="center"
android:id="#+id/linearLayout1">
<TextView
android:contentDescription="desk"
android:text="TextView"
android:id="#+id/list_background"
android:layout_height="wrap_content"
android:background="#AA000000"
android:layout_width="wrap_content"></TextView>
<TextView
android:id="#+id/m_popcorn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="spilled popcorn"></TextView>
<TextView
android:id="#+id/m_keyhole"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="keyhole"></TextView>
<TextView
android:id="#+id/m_pistol"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="pistol"></TextView>
<TextView
android:id="#+id/m_cat"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="cat"></TextView>
<TextView
android:id="#+id/m_pen"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="pen"></TextView>
</LinearLayout>
<ImageView
android:contentDescription="desk"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/viola_desmond_pic"
android:src="#drawable/icon"
android:layout_alignParentRight="true"></ImageView>
</RelativeLayout>

Categories

Resources