Sadeq Nameni Sadeq Nameni - 1 month ago 9
Android Question

how to set position for button in cardview

I have a few button in cardview but i can't drag it to anywhere i want.
in fact i want set , "next" button of media player to right of "play" button .

this is my xml code :



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="90dp"
app:cardBackgroundColor="?attr/colorPrimaryDark"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:cardCornerRadius="0dp"
app:cardElevation="12dp">

<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal|center_vertical"
android:background="@mipmap/play" />

<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@mipmap/next"
android:layout_gravity="center_vertical|end"/>

<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@mipmap/previous"
android:layout_gravity="center_vertical|start"/>

<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar2"
android:max="100"/>

</android.support.v7.widget.CardView>

</RelativeLayout>





it's result :

pic result

and what i want is :

what i want image

Answer

use this one:

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="90dp"
        app:cardBackgroundColor="?attr/colorPrimaryDark"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        app:cardCornerRadius="0dp"
        app:cardElevation="12dp">

<LinearLayout android:layout_width="wrap_content"
        android:layout_height="140dp"
        android:orientation="horizontal">

    <Button
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_weight="1"
        android:background="@mipmap/next"/>
    <Button
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="30dp"
        android:background="@mipmap/play" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="30dp"
        android:background="@mipmap/previous"/>
    </LinearLayout>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar2"
        android:max="100"/>

</android.support.v7.widget.CardView>