How to design a list item of listview - android-layout

I have a list view with Two text labels and three image buttons on each row. Visually, I want each row to look like this:
But I can't get this to work in my layout. This is what I'm doing right now. Even though the two labels are showing up ok, the buttons are not showing as I want them to.
Question
How can I align the buttons as in the mockup?
<TextView
android:id="#+id/color_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="15dip"
android:paddingLeft="5dip"
android:paddingTop="15dip"
android:textColor="#000000"
android:textSize="16dip"
android:layout_toRightOf="#+id/track_no"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="#id/shade_count"
android:layout_below="#id/shade_count"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/shade_count"
style="#style/ListSubtitleText"
android:textColor="#ff868686"
android:layout_width="0dp"
android:layout_weight="1"
android:paddingLeft="5dip"
android:singleLine="true" />
</LinearLayout>
<ImageButton
android:id="#+id/star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/star"/>
<ImageButton
android:id="#+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:src="#drawable/share"/>
<ImageButton
android:id="#+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/delete" />

try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:layout_marginTop="1dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red Color"
android:textColor="#000000"
android:paddingLeft="5dip"
android:textSize="16dip"
android:paddingTop="15dip"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this color has 20 shodes"
android:textColor="#ff868686"
android:paddingLeft="5dip"
android:paddingTop="15dip"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dip"
android:src="#drawable/star" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dip"
android:src="#drawable/share" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dip"
android:src="#drawable/delete" />
</LinearLayout>
</LinearLayout>

Try This:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="1dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingTop="15dip"
android:text="Red Color"
android:textColor="#000000"
android:textSize="16dip" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingTop="15dip"
android:text="this color has 20 shodes"
android:textColor="#ff868686" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="38dp" >
<ImageView
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/star" />
<ImageView
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageButton1"
android:src="#drawable/share" />
<ImageView
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageButton2"
android:src="#drawable/delete" />
</RelativeLayout>
</RelativeLayout>

Related

how to design responsive image button & layout by using android studio?

i am new to android development . I designed one parking app , but the layout is not responsive to all mobile devices.
I tried to make responsive image buttons by using 9patch png images & by taking different drawable folder(hdpi,mdpi,xhdpi) . But both are not working for large screen devices.
This is one sample xml file:
<?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/background"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/exit"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:src="#drawable/exit1"
android:onClick="on_Bexit"
android:layout_alignTop="#+id/home0"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/home0"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:src="#drawable/home1"
android:onClick="on_Bhome0"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/car"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:src="#drawable/c4"
android:onClick="on_Bcar"
android:cropToPadding="true"
android:nestedScrollingEnabled="true"
android:layout_alignBottom="#+id/textView5"
android:layout_alignLeft="#+id/bike"
android:layout_alignStart="#+id/bike" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bike"
android:layout_gravity="center_vertical"
android:src="#drawable/b3"
android:background="#android:color/transparent"
android:onClick="on_Bbike"
android:layout_above="#+id/exit"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ENTRY "
android:id="#+id/textView"
android:textColor="#8dacbe"
android:textStyle="bold"
android:textSize="35dp"
android:layout_above="#+id/car"
android:layout_toLeftOf="#+id/textView6"
android:layout_toStartOf="#+id/textView6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/bike_count"
android:text="90"
android:textColor="#140441"
android:textSize="30dp"
android:textStyle="bold|italic"
android:layout_alignBottom="#+id/bike"
android:layout_toLeftOf="#+id/exit"
android:layout_toStartOf="#+id/exit"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/car_count"
android:text="120"
android:textStyle="bold|italic"
android:textColor="#140441"
android:textSize="30dp"
android:layout_alignBottom="#+id/car"
android:layout_alignRight="#+id/bike_count"
android:layout_alignEnd="#+id/bike_count" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView5"
android:visibility="invisible"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/T_areadis"
android:hint="Parking area id and name"
android:textColor="#8dacbe"
android:text="kharghar"
android:textSize="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PAGE"
android:id="#+id/textView6"
android:textColor="#005384"
android:textSize="40dp"
android:textAlignment="center"
android:fontFamily="#string/abc_action_bar_home_description"
android:textStyle="bold"
android:layout_alignTop="#+id/textView"
android:layout_toRightOf="#+id/car_count"
android:layout_toEndOf="#+id/car_count" />
</RelativeLayout>
Please kindly help me out.
Large screen devices use xxhdpi.
How to has equal width
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="#+id/exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:onClick="on_Bexit"
android:src="#drawable/icon_login" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ENTRY "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#8dacbe"
android:textSize="35dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="#+id/home0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:onClick="on_Bhome0"
android:src="#drawable/icon_login" />
<TextView
android:id="#+id/bike_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="90"
android:textColor="#140441"
android:textSize="30dp"
android:textStyle="bold|italic" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="#+id/car"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:onClick="on_Bcar"
android:src="#drawable/icon_login" />
<TextView
android:id="#+id/car_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="120"
android:textColor="#140441"
android:textSize="30dp"
android:textStyle="bold|italic" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageButton
android:id="#+id/bike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
android:background="#android:color/transparent"
android:onClick="on_Bbike"
android:src="#drawable/icon_login" />
<TextView
android:id="#+id/T_areadis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Parking area id and name"
android:text="kharghar"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#8dacbe"
android:textSize="30dp" />
</LinearLayout>

How to design a layout similar to twitter's reply to a tweet android

On my app I when a user clicks on an item on the listview on the postmessageActivtiy it takes them to commentActivity , so I have been trying to design a layout that is similar to twitter ‘s reply to a tweet activity .On the comment side I have textviews that displays the postmessage and the user name of the user who posted it , below that I have a listView that is used to display the comments , below the listview I have a textEdit and a Postbutton aligned to the right of the text edit. The problem I am facing is that the layout doesn’t look right ,the listviews that displays the message and the username remain still on the same position whle the listview below scrolls up and down.How do I make the whole thing scroll up and down together?
<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"
tools:context="com.example.machimanapc.howzit.CommentActivity">
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageButton
android:id="#+id/imgBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_left_white"
android:background="?android:selectableItemBackground"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/reply"
android:textColor="#color/textColorPrimary"
android:layout_centerInParent="true"
android:textSize="25sp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/content"
android:layout_marginTop="5dp"
android:layout_below="#+id/header">
<TextView
android:id="#+id/txtUsername_view_Respond"
android:textColor="#color/colorPrimaryDark"
android:textStyle="bold"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textSize="6pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/stuff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/txtUsername_view_Respond"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="end">
<TextView
android:id="#+id/txtContent_view_Respond"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:textSize="6pt"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:layout_gravity="end">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:src="#drawable/ic_action_up"
android:background="?android:selectableItemBackground"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_down"
android:background="?android:selectableItemBackground"
/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/stuff">
<TextView
android:id="#+id/txtTimestamp_Reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/Timestamp"
android:textSize="#dimen/feed_item_timestamp"/>
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/posts_list_view"
android:layout_below="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
/>
<RelativeLayout
android:id="#+id/footer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/textColorPrimary"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/txtEdit_Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:hint="#string/prompt_reply"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="13dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/txtCharacter_count"
android:layout_toStartOf="#+id/txtCharacter_count"
android:inputType="textMultiLine"
android:singleLine="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnPost"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_centerInParent="true"
android:text="#string/prompt_post"
android:background="#drawable/newrounded"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<TextView
android:id="#+id/txtCharacter_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/btnPost"
android:layout_toStartOf="#+id/btnPost"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:text="#string/character_count_placeholder"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:gravity="center"
android:layout_marginTop="25dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"/>
</RelativeLayout>

Insert ImageView inside ListItem

I have the following code which show me a listitem with name, score, sex, age and country:
<?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"
android:padding="10dip" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="16sp"
android:textStyle="bold" />
<RatingBar
android:id="#+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:numStars="5"
android:rating="2.0" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="left"
android:orientation="vertical" >
<TextView
android:id="#+id/text_last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="#+id/text_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="#+id/text_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
And this code looks like:
What I want to do now is to add an image profile and show the list item like following:
How could I modify my code to adapt the imageview. I have tryied several configuration of ImageView with no succes.
Thanks
<?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"
android:padding="10dip" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView1" >
<TextView
android:id="#+id/text_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="16sp"
android:textStyle="bold" />
<RatingBar
android:id="#+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:numStars="5"
android:rating="2.0" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout1"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imageView1"
android:gravity="left"
android:orientation="vertical" >
<TextView
android:id="#+id/text_last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="#+id/text_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="#+id/text_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
Try this..

How to center a LinearLayout in RelativeLayout?

I would like to center a LinearLayout in a RelativeLayout but i have a problem, the margin-bottom stays attached to bottom. Here is the view :
http://nsa33.casimages.com/img/2013/03/12//130312103139937791.png
And here is the code of the layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/group_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/carreGlobalInterieur"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/grisTresClair" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/border_deals"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/GroupLigneOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/grisClair"
android:orientation="vertical" >
<TextView
android:id="#+id/CategorieDeal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="My Category"
android:textColor="#color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/nouveauPrixVert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10.99 €"
android:textColor="#color/green"
android:textStyle="bold" />
<TextView
android:id="#+id/ancienPrixRouge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="6dp"
android:text="20.90 €"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/red"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/reductionPrix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:text="(-34%)"
android:textColor="#color/red"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/ligneTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:orientation="vertical" >
<TextView
android:id="#+id/titreEnGros"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginTop="3dp"
android:text="Here is an example of a compleete title in a TextView Android"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textSize="16sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/ligneFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:orientation="vertical" >
<TextView
android:id="#+id/dateAjout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="il y a 2 heures" />
<TextView
android:id="#+id/siteWeb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="Amazon" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
If you have some ideas to center the block, please help me !
When using the RelativeLayout, you can use android:layout_centerInParent="true", which will do what it says, center it inside its parent.

Align Linear Layout to the bottom

I have a layout and I want the last LinearLayout to be aligned on the very bottom. I attempted to set the gravity and the android:layout_marginbottom=0dp and neither one seems to align it to the bottom.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".ItemDetailActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="154dp" >
<ImageView
android:id="#+id/albumArt"
android:layout_width="140dp"
android:layout_height="138dp"
android:src="#drawable/stealyourface" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill_horizontal|center"
android:orientation="vertical" >
<TextView
android:id="#+id/artistName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="#dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#E6E6E6" />
<TextView
android:id="#+id/showLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
<TextView
android:id="#+id/showDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
<TextView
android:id="#+id/runningSong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#E6E6E6" />
</LinearLayout>
<TextView
android:id="#+id/currentlyPlaying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/TwentyPixels"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#E6E6E6" />
</LinearLayout>
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="214dp"
android:background="#000000" >
<LinearLayout
android:id="#+id/songList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<!-- Player Buttons -->
**<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:layout_marginBottom="0dp">
<RelativeLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:background="#layout/rounded_corner"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<!-- Previous Button -->
<!-- Backward Button -->
<!-- Play Button -->
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnNext"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btnBackward"
android:background="#null"
android:src="#drawable/btn_play" />
<!-- Forward Button -->
<!-- Next Button -->
<ImageButton
android:id="#+id/btnPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnPlay"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#null"
android:src="#drawable/btn_previous" />
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPrevious"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btnPrevious"
android:background="#null"
android:src="#drawable/btn_backward" />
<ImageButton
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignTop="#+id/btnForward"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:layout_toRightOf="#+id/btnForward"
android:background="#null"
android:src="#drawable/btn_next" />
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btnPlay"
android:background="#null"
android:src="#drawable/btn_forward" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>**
You have to use android:layout_gravity to do that, not android:gravity.
http://developer.android.com/reference/android/widget/FrameLayout.html
layout_gravity specifies the gravity in respect to the parent, gravity controls the placement of the content in the view itself.
You should take a relative layout as inner layout of linear layout. Like this example. I hope its useful for you.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/mainact"
android:weightSum="6" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:clickable="true"
android:onClick="func"
android:src="#drawable/somnath" />
<ImageView
android:id="#+id/imageView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:clickable="true"
android:onClick="func"
android:src="#drawable/ghrishneshwar" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/mallikarjun" />
<ImageView
android:id="#+id/imageView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/kedarnath" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/mahakaleshwar" />
<ImageView
android:id="#+id/imageView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/trayambkeshwar" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/omkareshwar" />
<ImageView
android:id="#+id/imageView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/kashim" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="90dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/vaidyanath" />
<ImageView
android:id="#+id/imageView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="90dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/nageshwar" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="170dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/bhimashankar" />
<ImageView
android:id="#+id/imageView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="170dp"
android:clickable="true"
android:onClick="func"
android:src="#drawable/rameshwaram" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Resources