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>
Related
How to customize FrameLayout, I have to make screen like this:
and i have made this :
So now i want to know, How can i achieve above Layout
How to show icon on top, like in above screen (Path)
How to place text above circles, like in above screen (Dark Text: Remember Life) (Light Text: Instantly ....)
How to place buttons below circles, like in above screen (Register & Login)
Here is my XML, in which i am using FrameLayout, see below:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:sidebuffer="3" >
</com.indianic.viewflipperdemo.widget.ViewFlow>
<com.indianic.viewflipperdemo.widget.CircleFlowIndicator
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:padding="10dip"
android:layout_marginBottom="10dip"
app:inactiveType="stroke" />
</FrameLayout>
Finally, I achieved my target, I used both the Layouts [Relative Layout and Linear Layout] to organize widgets, see complete XML :
circle_layout.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:sidebuffer="3" >
</com.indianic.viewflipperdemo.widget.ViewFlow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_centerHorizontal="true"
android:text="Remember Life"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/viewflowindic"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:padding="5dp"
android:text="Instantly search memories of friends, season, birthdays, and more"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp" >
<Button
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="Register"
android:textColor="#000000" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="Login"
android:textColor="#000000" />
</LinearLayout>
<com.indianic.viewflipperdemo.widget.CircleFlowIndicator
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:padding="20dp"
app:inactiveType="stroke" />
</RelativeLayout>
And look at this awesome screenshot:
Use RelativeLayout instead FrameLayout. You will be more free with elements positions.
Relative Layout
Something like this you can do it
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:sidebuffer="3" />
<View
android:id="#+id/center"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/center"
android:padding="10dp"/>
<Button
android:id="#+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/center"
android:padding="10dp"/>
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_register"
android:layout_gravity="bottom|center_horizontal"
android:padding="10dip"
android:layout_marginBottom="10dip"
app:inactiveType="stroke" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/viewflowindic"
android:layout_centerHorizontal="true"
android:text="description"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/description"
android:layout_centerHorizontal="true"
android:text="title"/>
</RelativeLayout>
btw use match_parent instead fill_parent.
Use RelativeLayout to organize views. For implementing view pager indicator try this link
https://github.com/JakeWharton/Android-ViewPagerIndicator
Sample
<?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">
//You can put an image view or text view to show your app name
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Path"
android:id="#+id/title"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"/>
**// Try view pager indicator here.**
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:weightSum="2"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="#+id/">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_weight="1"
android:id="#+id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_weight="1"
android:id="#+id/button2"/>
</LinearLayout>
</RelativeLayout>
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
I want to display an ImageView then her TextView details followed by an other ImageView and her TextView details and then a text view and under them an ImageView then her TextView. So i put 2 child LinearLayouts that has orientation set to horizontal and the parent with orientation vertical but the second child LinearLayout is not appearing at all I don't know why. Thank you for helping. This is my activity.xml :
<?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="#drawable/fondgris"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageTypeWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/bugicon" />
<TextView
android:id="#+id/typeWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imagePriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/priorityhigh" />
<TextView
android:id="#+id/priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/statusopen" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/priority"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Your linearLayout1 has the property android:orientation="vertical" but then the very first child (linearLayout2) has android:layout_height="match_parent", which means the second child (linearLayout3) will have no space since first one will take over full height of the parent.
So you can change both children to have android:layout_height="wrap_content" and maybe add android:layout_weight="1" for both if you want.
The content is larger than the screen and it is hidden. You must use ScrollView.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewPort="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/fondgris"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageTypeWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/bugicon" />
<TextView
android:id="#+id/typeWorkitem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imagePriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/priorityhigh" />
<TextView
android:id="#+id/priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:src="#drawable/statusopen" />
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/priority"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Not sure if I'm understanding this correctly but from what you describe I would try using a relative layout as your parent and creating linear layouts inside of that that are relative to each other (one on top of the other).
I have a problem with my xml for android.
I have this layout to use it in each line of a Listview (that works fine).
I want to put two lines (head and body) of text, and align Right of the first line I have to put two ImageView. (Also have first of all a hidden textView)
Something like this:
My problem is when I try to put both imageViews (with only one it shows fine, but with two don't show nothing).
this is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:src="#drawable/new_group" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
sorry for my english and thank you in advance!
If I am understanding correctly then I believe this should be close to what you are looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="gone" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/TvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Test"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:src="#drawable/new_messages" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/ImgNewConvGroup"
android:gravity="right"
android:src="#drawable/new_group" />
</RelativeLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="22sp"
android:textStyle="normal" />
</LinearLayout>
Try it out and let me know if that works for you, I changed the inner layout from LinearLayout to RelativeLayout and created what I believe you are looking for in relational locations.
Note: Be cautious of your TextView extending far enough to go behind the ImageViews, if that happens then it might be better to (set for the ImageViews):
android:layout_below="#+id/TvName"
on both and remove:
android:layout_centerVertical="true"
<TextView
android:id="#+id/TvIdGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TV"
android:textSize="12sp"
android:textStyle="bold"
android:visibility="visible" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/TvName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="TVName"
android:textSize="30sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImgNewConvGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/ImgNewGroup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="right"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:id="#+id/TvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TVDescription"
android:textSize="22sp"
android:textStyle="normal" />
Take a look if is what are you looking for.
Is a lot of code just will write the structure
<LinearLayout android:orientation="vertical">
<LinearLayout android:orientation="horizontal">
<LinearLayout android:orientation="horizontal">
<TextView/>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:gravity="right">
<ImageView/>
<ImageView/>
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="vertical">
<TextView/>
</LinearLayout>
</LinearLayout>
For some reason I'm having a hell of a time with designing using eclipse and android SDK. Making layouts is painfully hard and not as easy as WPF/Visual Studio.
I am trying to accomplish the following:
Top: what I have
Bottom: what I want to achieve
http://imgur.com/AsaTuGq
Current code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="18sp"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:textSize="18sp"
/>
</LinearLayout>
Edit:
I've also tried using Vertical LinearLayout within a Horizontal LinearLayout but that just produced a lot of errors.
Edit2:
What's with the negative rating?
Edit3:
Tried this link: http://android-developers.blogspot.ca/2009/02/android-layout-tricks-1.html
Replacing the image with a textview but the date just aligns with the top row.. hmm
You should use a RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="false"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
I would suggest a RelativeLayout for this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:textIsSelectable="false"
android:id="#+id/line1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="18sp"
android:layout_weight="1"
android:textStyle="bold"
android:layout_alignParentLeft="true"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_below="#_id/line1"
/>
<TextView
android:textIsSelectable="false"
android:id="#+id/line3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_alignParentRight="true"
android:textSize="18sp"
/>
</RelativeLayout>
Changes:
Changed LinearLayout to RelativeLayout used android:layout_alignParentLeft="true" for the first two lines and android:layout_below="#+id/line1" for the second line. Moved the date to the right with android:layout_alignParentRight="true" and android:gravity="center_vertical" Hope this works for what you need.