the sides of my activity change - android

Every time I work with the emulator the app is fine, but when I send it to its sides it always turns upside down and everything on the right goes to the left and everything on the left goes to the right. can you please try to help me figure out what do I need to do in order to make this stop, so the app in my phone will be like the emulator?
example:
the activity in my phone
Example:
the activity in the emulator
here is the xml code
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="settings"
android:textColor="#0000FF"
android:textSize="50dp"
android:textAlignment="center"
android:textStyle="italic"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="choose your level"
android:textColor="#3300FF"
android:textSize="30dp"
android:textStyle="bold"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<RadioButton
android:id="#+id/begginer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="begginer"
android:textSize="30dp"
/>
<RadioButton
android:id="#+id/pro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="professional"
android:textSize="30dp" />
<RadioButton
android:id="#+id/WorldClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WorldClass"
android:textSize="30dp" />
<RadioButton
android:id="#+id/Legendery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Legendery"
android:textSize="30dp" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="enter your name"
android:textColor="#3300FF"
android:textSize="27dp"
android:textStyle="bold"
android:layout_weight="1"
/>
<EditText
android:textSize="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/nameid"
android:textColor="#FFFFFF"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:scaleType="centerCrop"
android:src="#drawable/tetrisstartgamebutton"
android:onClick="start"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="right|bottom"
android:orientation="vertical" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:onClick="menu"
android:layout_marginBottom="20dp"
android:layout_marginRight="40dp"
android:scaleType="centerCrop"
android:src="#drawable/aaaaaa"
android:id="#+id/BackToTheMenu"/>
</LinearLayout>

One reason could be because Force RTL layout direction is enabled
So check in device if you have it as enabled (Settings > Developer Options > Force RTL layout direction) and disable it.
The cause could be related to RTL o something like that, greetings

Related

Android Studio - HorizontalScollView not moving

I am doing some Android Studio courses. As part of this I am working on a mock-up music player app. The app should be mostly XML as not functionality needs to be added.
I am trying to build e Discover (new music) screen, where you have media like views. To do this, I want to implement an HorizontalScrollView.
The problem is that my scroll view doesn't move. The xml code looks fine to me and I also googled this but did not find anything that would help my situation.
Would very much appreciate some clarification on this. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.alexcojocaru.vibes.Discover">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Recommendations"
android:textColor="#cc3300" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:padding="5px"
android:scrollbars="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="5px"
android:src="#drawable/bear" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="My Name is Bear"
android:textColor="#000000"
android:textSize="11sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Nahko"
android:textSize="10sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="13px">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="6px"
android:src="#drawable/omam" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Beneath The Skin"
android:textColor="#000000"
android:textSize="11sp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Of Monsters and Men"
android:textSize="10sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="13px">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="6px"
android:src="#drawable/jmj" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Essential Recollection"
android:textColor="#000000"
android:textSize="11sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Jean-Michel Jarre"
android:textSize="10sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="13px">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:padding="6px"
android:src="#drawable/ram" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Random Access Memories"
android:textColor="#000000"
android:textSize="11sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="Daft Punk"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
I ran the above code and it works by default.
I think the problem is that if the layout fits fully on screen then you might not be able to see the scroll.
Suggesting to test on a smaller screen.
P.S:Not enough rep for comments.
Please change HorizontalScrollView as follows
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:padding="5px"
android:scrollbars="horizontal">

Expand and Collapase in Android

I want to create a Layout that have the feature of expand and collapse .Expand should be like that at a time only one row can be expanded ,if user clicks on other first should be closed by itself.In each row i have to show different layout design .
Please help me in this ,i have searched but i am not getting i how could i create this functionality .Please take this as a reference how it will be like .Please suggest me the best approach to get this
You can use a lib Accordion-View screenshot is :
I have implemented some code as the answer suggested by #Super User. So from that i think you will sure get your solution.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:accordion="http://schemas.android.com/apk/res-auto/com.sentaca.android.accordion"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/main_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#ff0000"
android:orientation="horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Offline Booking Request"
android:textColor="#fff"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<com.sentaca.android.accordion.widget.AccordionView
android:id="#+id/accordion_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
accordion:header_layout_fold_button_id="#id/foldButton"
accordion:header_layout_id="#layout/accordion_header"
accordion:header_layout_label_id="#id/foldText"
accordion:section_bottom="#layout/accordion_footer"
accordion:section_container="#layout/accordion_section"
accordion:section_container_parent="#id/section_content"
accordion:section_headers="#array/accordion_sections"
accordion:section_visibility="#array/accordion_visibility"
android:background="#fff5f5f5"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please specify offline car details if you need any cars of travels"
android:textSize="14sp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="45dp"
android:text="Plase click the checkbox to send the details"
android:textColor="#ff0000" />
<include layout="#layout/radio" >
</include>
</LinearLayout>
<LinearLayout
android:id="#+id/example_get_by_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 3" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 4" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 4" />
</com.sentaca.android.accordion.widget.AccordionView>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Review" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Confirm" />
</LinearLayout>
</LinearLayout>
Now just remember one thing whenever you want to add layout items then add item in Linear Layout and make different layout for different sections and after that include that layout in your Linear layout. I have tried for one section named radio.xml file which is included in Linear Layout above.
radio.xml
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:checked="true"
android:text="Domestic"
android:textColor="#ff0000" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="InterNational"
android:textColor="#ff0000" />
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Pick Up Location"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="DropLocation"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Car Type"
android:textColor="#000" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Remarks"
android:textColor="#000" />
<EditText
android:id="#+id/editText3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can start with ExpandableListView and customize it to your need. I think this would be a good way to start. Please follow a link below to customize ExpandableListView :
http://androidexample.com/Custom_Expandable_ListView_Tutorial_-_Android_Example/index.php?view=article_discription&aid=107&aaid=129
You can google for more links on customizing expandablelistview. Hope it helps.
You can use scaleAnimation where you can add in each section a layout panel and inside the layout textview or anything as your requirement. See this. Hope it might help you.
http://wwwpriyaandroid.blogspot.in/2013/10/accordion.html

Not happy with my Android UI layout

I am having a heck of time trying to get my UI to look the way I want. Here's what I've got ...
I would like the TextView, the XX:XX:XX, text font to be larger and centered between the EditText and Button. Also how come the user gets the phone keyboard instead of a qwerty keyboard to use to enter text?
Here's my layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
Use the following code to achieve what you want:......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18dp"
android:layout_weight="1"
android:text="#string/xx_xx_xx" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
please refer this xml all the changes is done tested is also done.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:textSize="18dp"
android:layout_weight="1"
android:text="hello" />
<Button
android:id="#+id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="add"/>
</LinearLayout>
<ListView
android:id="#+id/bookmark_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
You can use relative layout to do that. You can change the font size with android:textSize
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/new_bookmark_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:ems="10"
android:inputType="text" />
<TextView
android:id="#+id/new_bookmark_clock"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/new_bookmark_name"
android:layout_toLeftOf="#+id/btn_add_new_bookmark"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="#string/xx_xx_xx" />
<Button
android:id="#id/btn_add_new_bookmark"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/add"/>
</RelativeLayout>
Replace android:layout_gravity="center" by
android:gravity="center" in your TextView.
and regarding the keyboard layout, it looks like you are trying in the emulator. The emulator shows up 12pad keyboard in portrait mode. You can try in the device.
Please follow below, i have made a sample UI exactly what you have asked for using Relative Layout and by using minimum number of lines. Please have a look and check if can solve the purpose. I have also attached snapshot for the same.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:padding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/ed_name"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="number" />
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ed_name"
android:text="XX:XX:XX"
android:textSize="18dp" />
<Button
android:id="#+id/btn_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text=" add " />
</RelativeLayout>
</RelativeLayout>
About the keypad :Check it on actual device , the device will open its own default keypad.

RadioGroup/Button align

I'm trying to make an app with radio button which list them downwards which I have done. But I want them to be in the center of the page what ever screen size with the buttons all aligned. I've tried but its not in the center in all devices and I tried changing it but then the buttons wasn't align. Any help would be great. Thanks.
Code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundp"
android:orientation="vertical"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="20dip" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dip"
android:text="#string/question1"
android:textSize="30sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="10dip"
android:src="#drawable/square" />
<RadioGroup
android:id="#+id/q1_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="30dip"
android:paddingLeft="60dip" >
<RadioButton
android:id="#+id/q1a1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/shapetr"
android:textSize="25sp" />
<RadioButton
android:id="#+id/q1a2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/shapeci"
android:textSize="25sp" />
<RadioButton
android:id="#+id/q1a3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="#string/shapesq"
android:textSize="25sp" />
</RadioGroup>
use the layout_gravity of parent layout
See if this is what you are looking for
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="20dip" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dip"
android:text="question1"
android:textSize="30sp"
android:layout_above="#id/ivId" />
<ImageView
android:id="#+id/ivId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="10dip"
android:layout_above="#id/q1_group" />
<RadioGroup
android:id="#+id/q1_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:paddingBottom="30dip"
android:paddingLeft="60dip" >
<RadioButton
android:id="#+id/q1a1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="shapetr"
android:textSize="25sp" />
<RadioButton
android:id="#+id/q1a2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="shapeci"
android:textSize="25sp" />
<RadioButton
android:id="#+id/q1a3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:text="shapesq"
android:textSize="25sp" />
</RadioGroup>
</RelativeLayout>
I changed the parent layout to RelativeLayout. This way, the RadioGroup could be centered with
android:layout_centerInParent="true"
then I placed the other Views above with
android:layout_above="#id/idOfViewBelow"
which meant I had to give your ImageView an id which all Views really should have most of the time

Android LinearLayout Alignment

Being new to android I am still learning the intricacies of layouts. I am trying to create a simple bar on top of a map. For the most part this works fine.
My issue is that I want everything to be right aligned except for the Button which I want left aligned. I have tried quite a few combinations and am unable to get desired layout.
This is beginning to make me believe my structure as a whole is not correct. This seems like there should be an easy fix. What am I missing??
<LinearLayout
android:id="#+id/transparent_panel_hud"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right">
<Button
android:text="View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/arrow_down"
android:textSize="10sp"
android:drawablePadding="3dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="15dp" >
<TextView
android:id="#+id/latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:text="#string/default_latitude"
android:textSize="18sp" />
<TextView
android:id="#+id/longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/default_longitude"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/speed"
android:textSize="18sp" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/default_speed"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/heading"
android:textSize="18sp" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/default_heading"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>![screenie][1]
Do the following changes to your XML layout, you will get the output as you mentioned. Try this.
Remove the line android:gravity="right" in LinearLayout with id=transparent_panel_hud
Keep your Button in a LinearLayout as below.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left" >
<Button ... as you like />
</LinearLayout>
Keep your remaing 3 vertical LinearLayouts in a LinearLayout as below.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right" >
<LinearLayout vertical 1 ... as you like />
<LinearLayout vertical 2 ... as you like />
<LinearLayout vertical 3 ... as you like />
</LinearLayout>
I tested above changes to your code, its working. You too check it and let me know the result.
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/transparent_panel_hud"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:layout_alignParentLeft="true"
android:drawablePadding="3dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/rightlayout"
android:layout_alignParentRight="true"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="heading"
android:textSize="18sp" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="default_heading"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toLeftOf="#id/rightlayout"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="speed"
android:textSize="18sp" />
<TextView
android:id="#+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="default_speed"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>

Categories

Resources