【发布时间】:2016-07-16 16:54:53
【问题描述】:
每个项目应覆盖屏幕宽度的 70%。虽然 70% 的屏幕被填满,但我得到了 30% 的空白空间,下一个项目在它之后开始。 这是布局 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
app:cardCornerRadius="2dp"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:contentPadding="2dp"
app:layout_widthPercent="70%">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/image_test"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
</FrameLayout>
</android.support.v7.widget.CardView>
</android.support.percent.PercentRelativeLayout>
【问题讨论】:
-
尝试将
app:layout_widthPercent="70%"设置为您的PercentRelativeLayout并将CardView设置为match_parent -
问题不在于这个布局,而在于包含recyvlerview的布局。如果您在其中任何地方添加了 layout_margintop 任何类似的内容,请删除它
-
@IvanIvanov 如何为 PercentRelativeLayout 本身提供百分比宽度。我上次检查百分比是相对的。
标签: android android-recyclerview linearlayoutmanager