【发布时间】:2020-04-17 10:16:40
【问题描述】:
我希望 android:text="30" textview 在 Relativelayout 中处于中心位置。
但 android:layout_height="match_parent" 无法正常工作。 它看起来像“wrap_content”。
我正在尝试一切 我发现再添加一个 Relativelayout 并且可以正常工作。
- 文本“30”如何移动中心位置
- 为什么 match_parent 不起作用?
-
为什么再添加一个Relativelayout然后正常工作?
<androidx.core.widget.NestedScrollView android:id="@+id/product_grid" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="56dp" android:background="@color/productGridBackgroundColor" android:elevation="8dp" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false" android:clipToPadding="false" android:orientation="vertical" android:padding="24dp" android:paddingTop="16dp"> <com.google.android.material.card.MaterialCardView style="@style/Widget.MaterialComponents.CardView" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginLeft="@dimen/mtrl_card_spacing" android:layout_marginTop="@dimen/mtrl_card_spacing" android:layout_marginRight="@dimen/mtrl_card_spacing" android:minHeight="200dp"> **<!--height = match_parent not working-->** <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/home_card_title_level"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="30"/> </RelativeLayout> <!--**if this code added then work perfectly** <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"/> --> </com.google.android.material.card.MaterialCardView> </LinearLayout> </androidx.core.widget.NestedScrollView>
【问题讨论】:
标签: android height android-relativelayout