how to horizontally align 4 imageview with textview - android

I want to show four ImageViews horizontally together with TextViews. This is my screen and sample screen which I want to make. How can I do that?
XML code:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:layout_gravity="center"
>
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
<ImageView
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
<ImageView
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
<ImageView
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>

This works. I checked.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#CCCCCC"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hai there" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hai there" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hai there " />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hai there" />
</LinearLayout>
</LinearLayout>

You could wrap each ImageView/TextView pair in a LinearLayout like this:
<LinearLayout
android:id="#+id/group1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal>
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
/>
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#strings/my_text" />
</LinearLayout>
Edit: Added gravity attribute to keep everything in line

Use this
<?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="horizontal"
android:weightSum="1.0f" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight=".25f"
/>
<ImageView
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight=".25f"
/>
<ImageView
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight=".25f"
/>
<ImageView
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_weight=".25f"
/>
</LinearLayout>

Use TableRow and place all the images in that. Don't forget to give android:layout weight=1.
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</TableRow>

Related

Horizontal LinearLayout with HorizontalScrollView. ImageView after ScrollView gone

I have a Horizontal LinearLayout that have ImageView arrow left, HorizontalScrollView and ImageView arrow right. HorizontalScrollView have some ImageViews and I think it pushes the right arrow off the screen.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/arrowLeft
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrowLeft"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="55dp"
android:layout_marginTop="20dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/buttonToDoor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_todoor" />
<ImageView
android:id="#+id/buttonWomen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_women" />
<ImageView
android:id="#+id/buttonCommerce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_commerce" />
<ImageView
android:id="#+id/buttonPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_pause" />
<ImageView
android:id="#+id/buttonTrunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_trunk" />
<ImageView
android:id="#+id/buttonSnack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_snack" />
<ImageView
android:id="#+id/buttonSmoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_smoke" />
<ImageView
android:id="#+id/buttonWifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_wifi" />
<ImageView
android:id="#+id/buttonPackage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_package" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/arrowRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/rightArrow"
android:layout_marginTop="30dp"/>
</LinearLayout>
Image:
How could I show the right arrow?
Change the width of the HorizontalScrollView to 0dip and add to the attribute weight with value of 1
<HorizontalScrollView
android:layout_width="0dip"
android?layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="55dp"
android:layout_marginTop="20dp"
android:scrollbars="none">
This will make it fill all space available not ocuppied by other views (the arrows)
You can also achieve it by using Relative layout as a parent layout instead of Linear Layout , update your code as following:-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/arrowLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrowLeft"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"/>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/arrowLeft"
android:layout_toLeftOf="#+id/arrowRight"
android:layout_marginTop="20dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/buttonToDoor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_todoor" />
<ImageView
android:id="#+id/buttonWomen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_women" />
<ImageView
android:id="#+id/buttonCommerce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_commerce" />
<ImageView
android:id="#+id/buttonPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_pause" />
<ImageView
android:id="#+id/buttonTrunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_trunk" />
<ImageView
android:id="#+id/buttonSnack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_snack" />
<ImageView
android:id="#+id/buttonSmoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_smoke" />
<ImageView
android:id="#+id/buttonWifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_wifi" />
<ImageView
android:id="#+id/buttonPackage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/button_package" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/arrowRight"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrowLeft"
android:layout_marginTop="30dp"
android:layout_marginRight="20dp"/>
</RelativeLayout>
You can use simply weight-property of xml...
just paste this code in your xml....
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/arrowLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrowLeft" />
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/buttonToDoor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonWomen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonCommerce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonTrunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonSnack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonSmoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonWifi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/buttonPackage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="#+id/arrowRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/rightArrow" />
</LinearLayout>
</LinearLayout>

Aligning the ImageView to left the text view to center and checkbox to most right in android xml

I am making a activity layout using RelativeLayout i want the image view to be in most left and textview to be in center and checkbox to be in most right but layoutgravity and gravity is not working please can somebody help
<?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="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Time" />
<CheckBox
android:id="#+id/checkBoxTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:=""
android:gravity="right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Compass" />
<CheckBox
android:id="#+id/checkBoxCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textViewMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Map" />
<CheckBox
android:id="#+id/checkBoxMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
<?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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textViewTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageViewTime"
android:layout_weight="1"
android:gravity="center"
android:text="Time" />
<CheckBox
android:id="#+id/checkBoxTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:gravity="right" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<CheckBox
android:id="#+id/checkBoxCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:gravity="right" />
<TextView
android:id="#+id/textViewCompass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageViewCompass"
android:layout_weight="1"
android:gravity="center"
android:text="Compass" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:src="#drawable/ic_launcher" />
<CheckBox
android:id="#+id/checkBoxMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:gravity="right" />
<TextView
android:id="#+id/textViewMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageViewMap"
android:layout_weight="1"
android:gravity="center"
android:text="Map" />
</RelativeLayout>

Make layout scrollable

I want to make the given layout scrollable, so that the two buttons are fixed and the 4 imageViews can be scrolled. I tried the following code, but it messed up..kindly, help
Layout :
<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:orientation="horizontal" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:clickable="true"
android:src="#drawable/no_media" />
<ImageView
android:id="#+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv1"
android:clickable="true"
android:src="#drawable/no_media" />
<ImageView
android:id="#+id/iv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/iv1"
android:layout_marginTop="26dp"
android:clickable="true"
android:src="#drawable/no_media" />
<ImageView
android:id="#+id/iv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv3"
android:clickable="true"
android:src="#drawable/no_media" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginTop="14dp"
android:text="Click on the four images to take the pic" />
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="14dp"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Button" />
</LinearLayout>
take this code dude :) best of luck
<RelativeLayout 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:orientation="horizontal" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rel" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:clickable="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv1"
android:clickable="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/iv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/iv1"
android:layout_marginTop="26dp"
android:clickable="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/iv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv3"
android:clickable="true"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginTop="14dp"
android:text="Click on the four images to take the pic" />
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/rel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button2"
android:layout_margin="5dp"
android:text="Button" />
</RelativeLayout>
</RelativeLayout>
Try 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:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Click on the four images to take the pic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/iv1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/iv2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/iv3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/iv4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:layout_marginTop="15dp"
android:text="Button" />
</LinearLayout>
put fillviewport inside scrollview like this:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:clickable="true"
android:src="#drawable/no_media" />.....
Just remove RelativeLayout and put images directly into ScrollVIew

Listview item fits to row

I have a listview with two textviews in a row like name and result. I want to fit the textview to the row because I need to set a background color to the second textview.I have tried "match_parent"fill_parent"..etc
//items.xml
<ImageView
android:id="#+id/imgViewLogo"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/txtViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtViewDescription"
android:layout_alignBottom="#+id/txtViewDescription"
android:layout_marginLeft="6dp"
android:layout_toRightOf="#+id/imgViewLogo"
android:text="TextView"
android:textStyle="bold" />
<MyTextView
android:id="#+id/txtViewDescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgViewLogo"
android:layout_marginRight="33dp"
android:layout_gravity="center"
android:text="TextView"
android:textStyle="bold" />
<ImageView
android:id="#+id/temperrr"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/resultarrawnocolor" />
</RelativeLayout>
// listview.xml
<?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:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/gl1"
style="?android:attr/buttonStyleSmall"
android:layout_width="64dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/back"
android:gravity="center_vertical"
android:onClick="backMan" />
<TextView
android:id="#+id/textVie3"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/gl1"
android:background="#drawable/header_line" />
<Button
android:id="#+id/gl2"
style="?android:attr/buttonStyleSmall"
android:layout_width="64dp"
android:layout_height="40dp"
android:layout_above="#+id/textVie3"
android:layout_alignParentRight="true"
android:background="#drawable/info"
android:gravity="center_vertical"
android:onClick="info" />
<TextView
android:id="#+id/textVie1"
android:layout_width="135dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/gl2"
android:layout_alignBottom="#+id/gl2"
android:layout_centerHorizontal="true"
android:background="#drawable/uchek_header"
android:gravity="center" />
<TextView
android:id="#+id/bgnf1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textVie3"
android:background="#drawable/main_bag" />
<TextView
android:id="#+id/myTextView1"
android:layout_width="375dp"
android:layout_height="35dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/bgnf1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/textviewtableheader"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Result"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="#+id/btnemail"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/email"/>
<Button
android:id="#+id/btnsave"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/save"
/>
<Button
android:id="#+id/btnrec"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/myTextView1"
android:background="#drawable/rec"
/>
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btnemail"
android:layout_alignLeft="#+id/myTextView1"
android:layout_alignRight="#+id/myTextView1"
android:layout_below="#+id/myTextView1"
android:background="#color/White"
android:divider="#drawable/tabledivider"
android:dividerHeight="1dp"
android:listSelector="#drawable/listcolor"
tools:listitem="#android:layout/simple_list_item_1" >
</ListView>
</RelativeLayout>
If you want the height to be of icon size you can use this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:weightSum="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:background="#F00"
android:gravity="center_vertical"
android:text="Envelope" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:background="#990"
android:gravity="center_vertical"
android:text="1000ml/Dl" />
</LinearLayout>
</LinearLayout>
Try distributing the weight of ImageView , TextView , TextView and ImageView to get the desired result.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgViewLogo"
android:layout_width="22dip"
android:layout_height="22dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/temperrr"
android:layout_toRightOf="#+id/imgViewLogo"
android:orientation="horizontal"
android:weightSum="1.0" >
<TextView
android:id="#+id/txtViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/txtViewDescription"
android:layout_alignBottom="#+id/txtViewDescription"
android:layout_toRightOf="#+id/imgViewLogo"
android:layout_weight="0.5"
android:background="#ff0000"
android:text="TextView"
android:textStyle="bold" />
<TextView
android:id="#+id/txtViewDescription"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imgViewLogo"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="#ffff00"
android:text="TextView"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/temperrr"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
may be this will help, i edited the answer,check now

Android sliding Drawer for a button

I have a layout in the bottom of the screen which has five horizontal buttons, one of them is the 'more button'.
On the click of the 'more button' I want to open a sliding drawer with three buttons or textviews:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/global_bg" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/navicon_search" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_video" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_news" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_ecommerce" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imgMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_more" />
</LinearLayout>
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/top_color_bar" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ImageView01"
android:background="#drawable/global_masthead" >
<ImageView
android:id="#+id/imgbtnBackFromResetAddTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/topnav_backarrow_small" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Add Time"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgListOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/topnav_geomap_small" />
</RelativeLayout>
On click of 'imgMore', a sliding drawer should open with 3 buttons.
Please modify my layout to accomodate the changes.
I have tried this....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/global_bg" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/navicon_search" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_video" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_news" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_ecommerce" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_divider" />
<SlidingDrawer
android:id="#+id/SlidingDrawer"
android:layout_width="wrap_content"
android:layout_height="250dip"
android:content="#+id/contentLayout"
android:handle="#+id/imgMore"
android:orientation="horizontal"
android:padding="10dip" >
<ImageView
android:id="#+id/imgMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/nav_icon_more" />
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#cccccc"
android:gravity="center"
android:orientation="vertical"
android:padding="10dip" >
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="Option1" >
</Button>
<Button
android:id="#+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="Option2" >
</Button>
<Button
android:id="#+id/Button03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:text="Option3" >
</Button>
<Button>
</Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
<ImageView
android:id="#+id/ImageView01"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/top_color_bar" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ImageView01"
android:background="#drawable/global_masthead" >
<ImageView
android:id="#+id/imgbtnBackFromResetAddTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/topnav_backarrow_small" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Add Time"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imgListOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/topnav_geomap_small" />
</RelativeLayout>
See this example will help you. in this example that is only show you a button if you want to add text that is depen on you either it will be static or dynamic.
This is only for guide you.

Categories

Resources