У меня есть следующий код xml. Кнопка изображения не выравнивается ниже textView с запасом 5dp. Я думаю, что я ошибаюсь в понимании различных параметров макета. Relativelayout - это детское представление линейного выражения, имеющего несколько других представлений.Layout_Below не выполняется правильно в relativelayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40">
<com.github.lzyzsd.circleprogress.DonutProgress
android:id="@+id/amain_dp"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/amain_tv_currentsteps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="25sp" />
<ImageButton
android:id="@+id/amain_ib_whatsapp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/amain_tv_currentsteps"
android:background="@drawable/whatsapp_icon"/>
</RelativeLayout>
Это выход я получаю:
EDIT: код работает правильно, если layout_weight
параметр удаляется и фиксируется обеспечивается layout_height
параметр. Но хотелось бы понять, почему этот код не удается из-за layout_weight
EDIT: Полный код XML:
<ScrollView
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"
tools:context="in.jiyofit.basic_app.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/amain_tv_target"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:layout_weight="10" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40">
<com.github.lzyzsd.circleprogress.DonutProgress
android:id="@+id/amain_dp"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/amain_tv_currentsteps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="25sp" />
<ImageButton
android:id="@+id/amain_ib_whatsapp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/amain_tv_currentsteps"
android:background="@drawable/whatsapp_icon"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/amain_fl_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
android:layout_marginTop="20dp"/>
</LinearLayout>
Схема выглядит отлично на моем конце. Вы сняли скриншот в редакторе макетов Android Studio? – Shaishav
это с моего мобильного телефона. Добавьте другое представление с помощью 'layout_weight', которое может быть причиной. – suku
мой ответ должен работать –