I want something like this:
But so far, I get something like this:
Here is my main layout with gridview in it:
<?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="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#404040" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="clickBack" >
<ImageView
android:id="#+id/icon_type"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:src="#drawable/btn_arrow_back" />
<TextView
android:id="#+id/btn_back_main_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="#+id/icon_type"
android:background="#404040"
android:text="戻る"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:id="#+id/txt_big_title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="カレンダー"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/img_passcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/passcord_img" />
<TextView
android:id="#+id/txt_passcode_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img_passcode"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="ABCDEF"
android:textSize="15sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_passcode_note"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/img_passcode_circle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/btn_passcode_circle_pressed" />
<ImageView
android:id="#+id/img_passcode_circle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img_passcode_circle1"
android:background="#drawable/btn_passcode_circle_pressed" />
<ImageView
android:id="#+id/img_passcode_circle3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img_passcode_circle2"
android:background="#drawable/btn_passcode_circle_pressed" />
<ImageView
android:id="#+id/img_passcode_circle4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img_passcode_circle3"
android:background="#drawable/btn_passcode_circle_pressed" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<GridView
android:id="#+id/grid_passcode_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:numColumns="3"
>
</GridView>
</LinearLayout>
</LinearLayout>
And here is item layout to be inflated:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="50dp"
android:background="#drawable/border3" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:id="#+id/txt_passcode_keypad"
android:src="#drawable/border"
android:text="ABCD" />
<ImageView
android:id="#+id/img_passcode_keypad"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_passcode_delete" />
</RelativeLayout>
Please help me solve this problem!
Update: I added stretchmode like Koma Yip said, and also changed width and height of Relativelayout in "item layout" to wrap_content, but it did not work. It become like this:
Related
I inflate layout to listview and here is what I want:
But I always get something like this:
As you see, the button is always align at the bottom of parent. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<ImageView
android:id="#+id/img_icon_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp" />
<TextView
android:id="#+id/txt_title_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/img_icon_type"
android:text="TextView"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt_post_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_title_type"
android:layout_marginTop="16dp"
android:layout_toRightOf="#+id/img_icon_type"
android:text="TextView"
android:textSize="15sp" />
<TextView
android:id="#+id/txt_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_post_time"
android:layout_toRightOf="#+id/img_icon_type"
android:text="TextView"
android:textSize="15sp" />
<ImageView
android:id="#+id/img_edit_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="openPostMenu"
android:src="#drawable/btn_memo_menu" />
<TextView
android:id="#+id/txt_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img_icon_type"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="TextView"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_posted"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_below="#+id/txt_status"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/img_posted"
android:layout_alignRight="#+id/img_posted"
android:layout_below="#+id/img_posted" >
<RelativeLayout
android:id="#+id/btn_confirm_route"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#f2f2f2" >
<TextView
android:id="#+id/txt_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/現在地からのル一トを確認" />
<ImageView
android:layout_width="20sp"
android:layout_height="20sp"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/txt_address"
android:src="#drawable/btn_memo_route_search_pressed" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Please help me to fix this!Thank you!
I am using listiview for my application,in my listiview i set something like this
listitem1(Image)
listitem2(Image+Image)
Now issue is in my second row i want to get space between two images,but it is not working,following is my xml layout and screen shot of my output
listview_view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3F3F3"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/lnrsearchviews"
android:layout_below="#+id/imgshead"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/rect_search"
>
<!--<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/searchs"
android:layout_gravity="center_vertical"
/>-->
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/autosearchbyname"
android:hint="Search"
/>
</LinearLayout>
<!-- <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_shopbydept"
android:text="Shop By Departments"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_below="#+id/lnrsearchviews"
/>-->
<ListView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/list_menu"
android:layout_below="#+id/lnrsearchviews"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginBottom="20dp"
android:dividerHeight="8dp"
android:divider="#f3f3f3"
></ListView>
</RelativeLayout>
list_item
<?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="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:id="#+id/btntest"
android:background="#drawable/ab"
android:orientation="horizontal"
>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="180dp"
android:id="#+id/id"
android:background="#drawable/heads"
android:layout_weight="1.17">
<RelativeLayout
android:layout_height="40dp"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:padding="2dp"
android:text="abd"
android:id="#+id/txt_allproductsname"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:padding="2dp"
android:text="abddd"
android:id="#+id/txt_allproductsquty"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Mygetview
http://pastie.org/10289187#5
Try this as your list_item and use set visibility of the second ImageView to gone when you need to show only one image.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/first_imageview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#9ff0"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/second_imageview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#9ff0"
android:src="#drawable/ic_launcher" />
</LinearLayout>
I want to show four images as shown in given imaages . each image must be equally far apart from others I have tried a LinearLayout and use it weight property but all in sane.
I have eight icons, four for selected state and four for unselected state. I have tried many ways,
Thanks in Advance.
Image Icons are ..
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/article_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/forum_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/profile_icn"
android:padding="10dp"
android:layout_margin="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
I tried your code and modified a bit:
<?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" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="3" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="center" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/icon"
android:padding="10dp"
android:scaleType="fitXY" />
</LinearLayout>
</RelativeLayout>
Assigning android:weightSum="3" to container and weight 1 to all images works fine:
Output:
Check this layout, works exactly as you want. Just replace the image icons and background.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#517398" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_agenda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<ImageButton
android:id="#+id/image_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
OUTPUT
You can use weight attrib:
<?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="wrap_content"
android:background="#000000"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:src="#android:drawable/sym_action_chat" />
</LinearLayout>
output is like this:
Try this..
<?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" >
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom" />
<LinearLayout
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:scaleType="fitXY" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Screen
How to create layout with like this image. 50% text and rest of 50% divide by imageview textview and imageview what do i do?
please help me. I want to create screen like this image help me please.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="6"
android:background="#333333" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:layout_weight="0"
android:weightSum="1.5"
android:layout_marginBottom="1dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_marginRight="15dip"
android:layout_marginLeft="15dp"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:background="#drawable/layoutborder"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:layout_weight="0.8"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:paddingLeft="1dip"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:paddingTop="5dp"
android:textSize="10dip"
android:text=CONTAINS"
android:textColor="#FFffff" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:paddingLeft="1dip"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<TextView
android:id="#+id/imageView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:paddingLeft="1dip"
android:text="kurdfgkjdfuhfudshfkdshfdfhs
kdjhfjdshfkjdshfkdshfkshjdhfskjhfksdhfksjhfkjsdhfkjsdhfk
jshfshfshfdshdfshdkjfhsafkjsahdfksahdf" />
</LinearLayout>
</LinearLayout>
Try
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#333333"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="1dp"
android:layout_weight="1"
android:background="#color/blue"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:paddingLeft="1dp"
android:src="#drawable/login_down" />
<TextView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_weight="0.2"
android:paddingTop="5dp"
android:text="CONTAINS"
android:textColor="#FFffff"
android:textSize="10dip" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:paddingLeft="1dp"
android:src="#drawable/login_button" />
</LinearLayout>
<TextView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="1dp"
android:text="kurdfgkjdfuhfudshfkdshfdfhs
kdjhfjdshfkjdshfkdshfkshjdhfskjhfksdhfksjhfkjsdhfkjsdhfk
jshfshfshfdshdfshdkjfhsafkjsahdfksahdf" />
</LinearLayout>
Use as minimum layout as possible that will help in fast rendering. Try below code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgMainImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/txtsubImgTitle"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/textView1"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="TextView" />
<ImageView
android:id="#+id/imgSubImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/imgMainImage"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/txtsubImgTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imgSubImg"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:text="TextView" />
</RelativeLayout>
I want to center horizontally and vertically block L3 on this image, can you help me with the layout structure to use. ON the right side is current structure of the menu. Thanks.
Here is the layout.xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/BaseLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/mainmenu_background" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_background" />
<LinearLayout
android:id="#+id/l1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Top menu -->
<LinearLayout
android:id="#+id/l2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/TopMenuHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/main_menu_background_header"
android:gravity="left"
android:orientation="horizontal"
android:visibility="visible" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/logo" />
<LinearLayout
android:id="#+id/TopRightButtonsHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:visibility="visible" >
<RelativeLayout
android:id="#+id/sinscrire"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/login_registerbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_sinscrire_button" />
<TextView
android:id="#+id/sinscrire_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/cpr_sinscrite_title_text"
android:textColor="#color/cpr_menubutton_black"
android:textSize="#dimen/cpr_small_menubutton_title_text_size"
android:textStyle="bold|italic" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/connexion"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/login_loginbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_logout_button" />
<TextView
android:id="#+id/connexion_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/cpr_connexion_title_text"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_small_menubutton_title_text_size"
android:textStyle="bold|italic" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<!-- End of Top menu -->
<!-- Middle menu -->
<LinearLayout
android:id="#+id/l3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/MiddleMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<LinearLayout
android:id="#+id/MiddleLeftButtonsHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal"
android:visibility="visible" >
<RelativeLayout
android:id="#+id/Parametres"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/optionsmenu_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_options_button" />
<LinearLayout
android:id="#+id/options_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="left"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/options_icon" />
<TextView
android:id="#+id/parametres_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cpr_parametres_title_text"
android:textColor="#color/cpr_menubutton_black"
android:textSize="#dimen/cpr_small_menubutton_title_text_size"
android:textStyle="bold|italic" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/Aide"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/optionsmenu_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_help_button" />
<LinearLayout
android:id="#+id/help_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="left"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/help_icon" />
<TextView
android:id="#+id/aide_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cpr_aide_title_text"
android:textColor="#color/cpr_menubutton_black"
android:textSize="#dimen/cpr_small_menubutton_title_text_size"
android:textStyle="bold|italic" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/MiddleRightButtonsHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/MiddleLeftButtonsHolder"
android:orientation="horizontal"
android:visibility="visible" >
<RelativeLayout
android:id="#+id/Caisse"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/cashiericon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_cashier_button" />
<LinearLayout
android:id="#+id/caisse_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="left"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/cashier_icon" />
<TextView
android:id="#+id/caisse_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cpr_caisse_title_text"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_small_menubutton_title_text_size"
android:textStyle="bold|italic" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<!-- End of Middle menu -->
<!-- Main menu -->
<RelativeLayout
android:id="#+id/MainMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/MiddleMenu"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" >
<ImageView
android:id="#+id/main_menu_black_rect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/main_menu_black_rect" />
<RelativeLayout
android:id="#+id/play_for_real"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp" >
<ImageButton
android:id="#+id/realmoneybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitStart"
android:src="#drawable/main_menu_play_for_real_button" />
<ImageView
android:id="#+id/play_for_real_img_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/realmoneybutton"
android:layout_alignRight="#id/realmoneybutton"
android:background="#color/transparent"
android:src="#drawable/main_menu_play_for_real_button_icon" />
<LinearLayout
android:id="#+id/play_for_money_text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/play_for_real_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cpr_play_for_real_title_text"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_menubutton_title_text_size"
android:textStyle="bold" />
<TextView
android:id="#+id/play_for_real_desc"
android:layout_width="221dp"
android:layout_height="wrap_content"
android:text="#string/cpr_play_for_real_title_desc"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_menubutton_desc_text_size" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/play_for_fun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/play_for_real"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp" >
<ImageButton
android:id="#+id/playmoneybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_play_for_fun_button" />
<ImageView
android:id="#+id/play_for_fun_img_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/playmoneybutton"
android:layout_alignRight="#id/playmoneybutton"
android:background="#color/transparent"
android:src="#drawable/main_menu_play_for_fun_button_icon" />
<LinearLayout
android:id="#+id/play_for_fun_text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/play_for_fun_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cpr_play_for_fun_title_text"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_menubutton_title_text_size"
android:textStyle="bold" />
<TextView
android:id="#+id/play_for_fun_desc"
android:layout_width="221dp"
android:layout_height="wrap_content"
android:text="#string/cpr_play_for_fun_title_desc"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_menubutton_desc_text_size" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/tutoriel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/play_for_fun"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp" >
<ImageButton
android:id="#id/previewbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#color/transparent"
android:scaleType="fitXY"
android:src="#drawable/main_menu_tutorial_button" />
<TextView
android:id="#+id/tutoriel_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/cpr_tutoriel_title_text"
android:textColor="#color/cpr_menubutton_white"
android:textSize="#dimen/cpr_menubutton_title_text_size"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<!-- End of Main menu -->
</LinearLayout>
<!-- End of Main Container -->
</RelativeLayout>
Here is a Linear Layout with a Relative Layout centered inside.
Move your code from the "l3" layout to the "l4" layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#56a"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="l2" />
</LinearLayout>
<RelativeLayout
android:id="#+id/l3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#a56" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="l3" />
<RelativeLayout
android:id="#+id/l4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#5a6" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="l4" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>