Correct layout android - android

I am developing simple Android application. Here is the mockup of the layout I want to create (just to give you an idea).
On both sides there will be 4 pictures with words.
What would be the best way to do that? Here is what I have so far. Is that OK or is there any better way to do that?
<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="#B36E106F"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context=".AddRoute" >
<RelativeLayout
android:id="#+id/add_left_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#+id/imageView1"
android:text="From" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_marginTop="48dp"
android:layout_toLeftOf="#+id/textView1"
android:src="#drawable/abc" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView2"
android:layout_marginTop="54dp"
android:src="#drawable/abc" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView3"
android:layout_marginTop="47dp"
android:src="#drawable/abc" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/add_right_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_margin="5dp"
android:background="#0098FF" >
</RelativeLayout>
</LinearLayout>

you will love this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="#drawable/abc_menu_dropdown_panel_holo_light">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView" />
<TextView
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/right"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:background="#drawable/abc_spinner_ab_focused_holo_dark">
</LinearLayout>
</LinearLayout>
I am using the layout_weight trick to make the left linearLayout and right linearlayout to be the same width.
what you need to do is modify the style, backgournd, margin and padding.
reading the google android docs won`t get you pregnant,so do more reading.
google design guide for linearLayout and layout_weight

i would do it like this
<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="#B36E106F"
android:baselineAligned="false"
android:orientation="horizontal"
tools:context=".AddRoute" >
<LinearLayout
android:id="#+id/add_left_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:background="#0098FF"
android:orientation="vertical" >
<!-- Images here -->
</LinearLayout>
<LinearLayout
android:id="#+id/add_right_column"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="0.5"
android:background="#0098FF"
android:orientation="vertical" >
<!-- Images here -->
</LinearLayout>
</LinearLayout>
LinearLayout is a lot faster than RelativeLayout, at least if you use relative layouts features like alignToRightOf and similar methods.
But as your not using any features, why using it at all?
besides that you should change your weight to 0.5 as you want them to split the space equally. 100% => 1 except if you set a different weightSum

Since the number of the pictures on the both sides are determined. You can use a Horizontal LinearLayout with two Vertical LinearLayout inside it. And use the layout_weight attribute to let them split the parent layout equally. Like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
Put your image and textView in the 8 horizontalLinearLayout.
Then if the number of images is determined during the runtime, you can try staggereGridView.

Related

Android: Center two elements in a Linear Layout

I want that both elements are centered and without that stretching.
Also, it would be great if the weight was not that wide.
This is how it looks like:
Heres the code:
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/listColor"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/layout_item_value"
android:text="163,00"
android:textSize="18.2dp"
android:gravity="center_vertical|center_horizontal"
android:id="#+id/txtListValue"
android:textColor="#color/back"
/>
<ImageView
android:id="#+id/image_order"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:scaleX="0.4"
android:scaleY="0.4"
android:gravity="center_vertical|center_horizontal"
/>
Thank You in advance!
Its very simple, you can maintain it with the parent layout itself
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/txtListValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF1493"
android:text="163,00"
android:textColor="#000000"
android:textSize="30sp" />
<ImageView
android:id="#+id/image_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
try this layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="2">
<TextView
android:id="#+id/txtListValue"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF1493"
android:gravity="center_vertical|center_horizontal"
android:text="163,00"
android:textColor="#000000"
android:textSize="30sp" />
<ImageView
android:id="#+id/image_order"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:scaleX="0.4"
android:scaleY="0.4"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
Output:
You can use below API without weightsum...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FC226E"
android:gravity="center"
android:text="1,00"
android:textColor="#FFFFFF"
android:textSize="28sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>

Horizontal ScrollView in Eclipse

I am making an advertising application in Eclipse and wish to display scroller ad's in horizontal ScrollView. Also I need to rotate this scroller view after every 5 seconds.
The following is the configuration
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="vertical">
<ScrollView
android:id="#+id/hsHorizontalAds"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/llHorizontalAds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Please suggest.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="vertical">
<HorizontalScrollView
android:id="#+id/hsHorizontalAds"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/llHorizontalAds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Try like this way,this is what you looking for
<?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" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>

Android Linear Layout Split Screen with Scrollview

The following is my layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:layout_gravity="top"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:layout_weight="0.5"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:layout_marginLeft="50sp"
android:layout_marginBottom="5sp"
android:textSize="15sp"
android:textColor="#000000" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:src="#drawable/picframe" android:contentDescription="TODO"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="0.5"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
Basically I have 3 linear layouts
the first one is the size of the whole screen
the other two are inside the first and split the screen into two
the right hand layout displays a bitmap which works fine
The left hand layout displays a notes box
this all works fine but I want to make the left side scrollable so if you enter notes more than the height of the screen you can keep going and scroll down to see the rest
problem is it all works fine until I add the scrollview as above
the notes editbox and label disappear and cant be seen
If I remove the scrollview they come back
Any ideas where im going wrong?
As always any help appreciated
Mark
These are the changes you need to do in your xml
i.e. removing background color from scrollview and shifting linear layout background to scrollview and removing layout weight from linear layout and setting width as match_parent
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="0.5"
android:baselineAligned="false"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="0.5"
android:background="#ffffff"
android:fillViewport="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="0.5"
android:background="#F4F2F2"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5sp"
android:layout_marginLeft="50sp"
android:layout_marginTop="10sp"
android:gravity="left"
android:text="Notes:"
android:textColor="#000000"
android:textSize="15sp" />
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50sp"
android:layout_marginRight="50sp"
android:background="#ffffff"
android:ems="10"
android:textColor="#000000" >
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:contentDescription="TODO"
android:src="#drawable/image" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#FFFFFF"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
In you case equal weight is needed for child ScrollView and LinearLayout and set Scoll data to center of ScrollView :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F2F2"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Notes:"
android:textSize="15sp"
android:textColor="#000000"
android:layout_marginTop="5dp"/>
<EditText
android:id="#+id/notetext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textColor="#000000"
android:background="#ffffff"
android:layout_marginTop="5dp">
</EditText>
<ImageView
android:id="#+id/mImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/picframe"
android:contentDescription="TODO"
android:layout_marginTop="5dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:layout_weight="1"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
</LinearLayout>
</LinearLayout>
Give this one a try, you don't need to give 0dp to your child LinearLayout.
<ScrollView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F2F2"
android:orientation="vertical" >

How to build my menu for android devices

I'm working on my game menu for android and I'm stuck to apply my layout for all devices screen size.
Do I have to size my layout in dp or with weight ?
I'am aware of doing many layout in layout-large, layout-small... and drawable-hdpi, drawable-ldpi ... but I'm still stuck.
How you will do it?
You can find a skeleton of what I want :
http://imageshack.us/photo/my-images/14/menuskeleton.jpg/
Thank you !
I advise you to use the weight to keep interoperability with other formats tablet.
My solution :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#AAAAAA"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
tools:ignore="DisableBaselineAlignment" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
tools:ignore="NestedWeights" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shop"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ladder"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profil"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recap_All"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
tools:ignore="DisableBaselineAlignment" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical"
tools:ignore="NestedWeights" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:background="#DDDDDD"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAY"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
And result in picture :
I hope you have helped!
On this page of google developers, has a description of how to develop for different screen sizes.
http://developer.android.com/guide/practices/screens_support.html
And this page is the answer to your question about the size of your layout, it is between dp or weight.
http://developer.android.com/training/multiscreen/screendensities.html
See this also.
http://developer.android.com/training/multiscreen/index.html

How to do complex layout with scrollview

I need to perform this layout:
See image from:
https://lh3.googleusercontent.com/-_uW9jKzUY_M/UVWlL2SnNBI/AAAAAAAAAOw/geY-Q-vTsqY/s540/myImage+%283%29.png
Area 1 is a complex imbrication of linear / relative layouts
Area 2 is also complex, but would be contained in a scrollview
Area 3 contains 2 buttons in a vertical linear layout
How this can be achieved?
What about this?
<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="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.33" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</LinearLayout>
I found the answer myself.
I have to use the layout_above attribute and a main RelativeLayout.
See this example:
<RelativeLayout 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="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView1" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView2" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
</LinearLayout>
</RelativeLayout>

Categories

Resources