#android #android-layout #android-view #android-xml
Вопрос:
У меня есть такой макет в моем приложении. Черная цветная полоса под изображением-это View
элемент. Я хочу, чтобы эта высота полосы заполняла всю область под изображением.
Это мое layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@ id/layoutNote"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@ id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/_10sdp"
app:cardElevation="@dimen/_5sdp"
android:layout_margin="@dimen/_5sdp"
app:cardBackgroundColor="#C9E9FF"
android:padding="@dimen/_5sdp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@ id/imgNote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone"
app:riv_corner_radius_top_left="@dimen/_10sdp"
app:riv_corner_radius_top_right="@dimen/_10sdp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:minHeight="50dp"
android:layout_gravity="start"
android:id="@ id/colorBar"
android:layout_centerVertical="true"
android:background="@color/grad_23"
android:layout_alignParentStart="true"/>
<TextView
android:id="@ id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/_15ssp"
android:padding="@dimen/_5sdp"
android:layout_toEndOf="@id/colorBar"
android:fontFamily="@font/manrope_bold"
android:textColor="@color/lightGrey"/>
<TextView
android:id="@ id/tvWebLink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_below="@ id/tvTitle"
android:fontFamily="@font/manrope_bold"
android:paddingBottom="@dimen/_2sdp"
android:paddingStart="@dimen/_5sdp"
android:textColor="@color/ColorGray"
android:textSize="@dimen/_12ssp"
android:visibility="gone"
android:autoLink="web"/>
<TextView
android:id="@ id/tvDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/_11ssp"
android:layout_below="@id/tvWebLink"
android:paddingStart="@dimen/_10sdp"
android:paddingTop="@dimen/_5sdp"
android:paddingBottom="@dimen/_5sdp"
android:paddingEnd="@dimen/_5sdp"
android:fontFamily="@font/manrope_regular"
android:textColor="@color/ColorText"/>
<TextView
android:id="@ id/tvDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/_9ssp"
android:paddingStart="@dimen/_10sdp"
android:paddingBottom="@dimen/_5sdp"
android:layout_below="@id/tvDesc"
android:fontFamily="@font/manrope_regular"
android:textColor="@color/ColorText"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
В View
теге, когда я устанавливаю высоту, соответствующую родительскому, весь вид становится невидимым во время запуска приложения, поэтому я использую android:minHeight="50dp"
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:minHeight="50dp"
android:layout_gravity="start"
android:id="@ id/colorBar"
android:layout_centerVertical="true"
android:background="@color/grad_23"
android:layout_alignParentStart="true"/>
Я попробовал использовать LinearLayout
с layout_weight="1"
, что тоже не сработало. Есть идеи, как я мог бы это решить?
Комментарии:
1. Код должен просто нормально работать …. С этим нет проблем… его невозможно воспроизвести с помощью кода, который вы дали
2. Но если убрать минимальную высоту, то весь вид просто исчезнет.
3. Нет, это невозможно … либо вы должны добавить что-то еще в свой код, либо удалить что-то еще из своего кода… код, который вы упомянули, просто прекрасен
4. Почему бы не изменить компоновки (Линейные относительные) на ограничение? Код выглядит просто отлично, но ограничение даст вам гораздо больше контроля и производительности
5. Я изменил все на ConstraintLayout сейчас, и у меня та же проблема, представление не отображается, если я не дам ему минимальную высоту