Hello, I want to put a fragment below an object and the marginBottom to do it to another button, but if I put the layout_marginBottom code, the app closes
........................................................... ........................................................... ........................................................... ........................................................... ........................................................... ........................................................... ...................
the frameLayout is inside a relative
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".MainActivity">
<ImageButton
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="6dp"
android:layout_marginTop="10dp"
android:background="#F8F8F8"
app:srcCompat="@drawable/menu"
android:contentDescription="TODO" />
<ImageButton
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="6dp"
android:background="#F8F8F8"
app:srcCompat="@drawable/settings" />
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="80dp"
android:layout_marginBottom="9dp"
android:background="#FFFFFF"
app:srcCompat="@drawable/stop"
android:contentDescription="TODO" />
<ImageButton
android:id="@+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="22dp"
android:layout_marginBottom="9dp"
android:background="#FFFFFF"
app:srcCompat="@drawable/play"
android:contentDescription="TODO" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="201dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="106dp"
android:layout_marginEnd="31dp"
android:layout_marginBottom="59dp"
android:layout_toStartOf="@+id/textView2" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="11dp"
android:layout_marginBottom="59dp"
android:text="TextView"
android:textColor="@color/black"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="15dp"
android:layout_marginBottom="59dp"
android:text="TextView"
android:textColor="@color/black"/>
<TextView
android:id="@+id/onair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="108dp"
android:text="ONAIR"
android:textColor="@color/colorAccent"/>
<FrameLayout
android:id="@+id/contenedorFragments"
android:layout_width="match_parent"
android:layout_height="660dp"
android:layout_below="@id/settings"
android:layout_marginBottom="@+id/onair"/>
</RelativeLayout>
and the error that comes out is this:
2019-09-16 13:42:25.358 12603-12603/com.radio.shalommadrid E/AndroidRuntime: FATAL EXCEPTION: main Process: com.radio.shalommadrid, PID: 12603 java.lang.RuntimeException: Unable to start activity ComponentInfo{ com.radio.shalommadrid/com.radio.shalommadrid.MainActivity}: android.view.InflateException: Binary XML file line #101: Can't convert value at index 6 to dimension: type=0x12
The error you indicate in your question:
it is because you are defining an incorrect value in the property
android:layout_marginBottom
,in
android:layout_marginBottom
you must define a unit of measure and not an id from another viewHow can I place top and bottom objects in android?
If you are using a
RelativeLayout
, to place the Fragments container at the bottom (bottom
) you can use :Example:
To put the Fragments container on top you can use:
example:
You can do it like this, I have added the button that I guess you forgot to add
It's giving you shit because you can't add an object when you're defining the margins android:layout_marginBottom.
For this case, I would use a ConstraintLayout. I leave you a link to the official documentation so you can see how it is used.
This allows you to "anchor" the layout to other elements and force it to occupy the space you indicate.
https://developer.android.com/training/constraint-layout