我得到了一个加载在占位符视图中的cardview布局。到目前为止这么好,但是当没有边距/填充/对齐或其他什么时,cardview不会对齐顶部。我想我不会看到我的xml错误。我感谢你的帮助!
以下是我的cardview代码:
<android.support.percent.PercentFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5"
android:orientation="vertical">
<android.support.v7.widget.CardView
app:layout_widthPercent="94%"
app:layout_heightPercent="70%"
android:layout_gravity="center_horizontal"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="7dp"
app:cardElevation="2dp">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="match_parent">
<android.support.percent.PercentRelativeLayout
app:layout_widthPercent="100%"
app:layout_heightPercent="80%"
android:layout_gravity="bottom"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/typeTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="10%"
android:layout_weight="0.02"
android:gravity="center_horizontal"
android:text="type"
android:maxLines="3"
android:textColor="@color/colorPrimary"
android:textSize="14dp"
android:textStyle="bold" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profileImageView"
app:layout_widthPercent="30%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="20%"
app:layout_marginTopPercent="35%"
android:gravity="center_horizontal"
app:border_width="3dp" />
<TextView
android:id="@+id/descTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="70%"
android:text="jobkind"
android:gravity="center_horizontal"
android:textColor="@color/colorPrimary"
android:textSize="12dp"
android:textStyle="normal" />
<TextView
android:id="@+id/comTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="90%"
android:gravity="center_horizontal"
android:text="company"
android:textColor="@color/colorPrimary"
android:textSize="12dp"
android:textStyle="normal" />
</android.support.percent.PercentRelativeLayout>
<android.support.percent.PercentRelativeLayout
app:layout_widthPercent="100%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="80%">
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
android:layout_centerHorizontal="true"
app:layout_marginTopPercent="5%"
android:src="@drawable/place_icon" />
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="5%"
android:gravity="center"
android:src="@drawable/clock_icon" />
<TextView
android:id="@+id/durTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
android:text="duration"
android:gravity="center"
app:layout_marginTopPercent="50%"
android:textColor="@color/colorPrimary"
android:textSize="11dp"
android:textStyle="normal" />
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="68%"
app:layout_marginTopPercent="5%"
android:src="@drawable/euro" />
<TextView
android:id="@+id/placeTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="50%"
android:text="place"
android:gravity="center"
android:textSize="11dp"
android:layout_centerHorizontal="true"
android:textColor="@color/colorPrimary"
android:textStyle="normal" />
<TextView
android:id="@+id/salTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="50%"
android:text="salary"
android:gravity="center"
app:layout_marginLeftPercent="68%"
android:textColor="@color/colorPrimary"
android:textSize="11dp"
android:textStyle="normal" />
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.v7.widget.CardView>
</android.support.percent.PercentFrameLayout>
这是占位符视图,在我的cardview中加载
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
>
<com.mindorks.placeholderview.SwipePlaceHolderView
android:id="@+id/swipeView"
android:layout_width="match_parent"
app:layout_heightPercent="100%"
android:foregroundGravity="top"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_gravity="bottom"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="@+id/rejectBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/cancel" />
<!--android:background="@drawable/ic_cancel"-->
<ImageButton
android:id="@+id/acceptBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/check"
android:layout_marginLeft="30dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="78dp"
android:layout_gravity="center"
android:gravity="center">
</LinearLayout>
</com.mindorks.placeholderview.SwipePlaceHolderView>
</android.support.percent.PercentRelativeLayout>
占位符视图的预览图片
非常感谢你的帮助!
答案 0 :(得分:0)
尝试用以下内容替换您的cardview:
<android.support.percent.PercentFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:baselineAligned="false"
android:orientation="vertical">
<android.support.v7.widget.CardView
app:layout_widthPercent="94%"
app:layout_heightPercent="70%"
app:cardBackgroundColor="@color/colorWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content">
app:cardCornerRadius="7dp"
app:cardElevation="2dp">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="wrap_parent">
<android.support.percent.PercentRelativeLayout
app:layout_widthPercent="100%"
app:layout_heightPercent="80%"
android:layout_gravity="bottom"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/typeTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="10%"
android:layout_weight="0.02"
android:gravity="center_horizontal"
android:text="type"
android:maxLines="3"
android:textColor="@color/colorPrimary"
android:textSize="14dp"
android:textStyle="bold" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profileImageView"
app:layout_widthPercent="30%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="20%"
app:layout_marginTopPercent="35%"
android:gravity="center_horizontal"
app:border_width="3dp" />
<TextView
android:id="@+id/descTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="70%"
android:text="jobkind"
android:gravity="center_horizontal"
android:textColor="@color/colorPrimary"
android:textSize="12dp"
android:textStyle="normal" />
<TextView
android:id="@+id/comTxt"
app:layout_widthPercent="70%"
app:layout_heightPercent="15%"
app:layout_marginTopPercent="90%"
android:gravity="center_horizontal"
android:text="company"
android:textColor="@color/colorPrimary"
android:textSize="12dp"
android:textStyle="normal" />
</android.support.percent.PercentRelativeLayout>
<android.support.percent.PercentRelativeLayout
app:layout_widthPercent="100%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="80%">
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
android:layout_centerHorizontal="true"
app:layout_marginTopPercent="5%"
android:src="@drawable/place_icon" />
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="5%"
android:gravity="center"
android:src="@drawable/clock_icon" />
<TextView
android:id="@+id/durTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
android:text="duration"
android:gravity="center"
app:layout_marginTopPercent="50%"
android:textColor="@color/colorPrimary"
android:textSize="11dp"
android:textStyle="normal" />
<ImageView
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginLeftPercent="68%"
app:layout_marginTopPercent="5%"
android:src="@drawable/euro" />
<TextView
android:id="@+id/placeTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="50%"
android:text="place"
android:gravity="center"
android:textSize="11dp"
android:layout_centerHorizontal="true"
android:textColor="@color/colorPrimary"
android:textStyle="normal" />
<TextView
android:id="@+id/salTxt"
app:layout_widthPercent="33%"
app:layout_heightPercent="40%"
app:layout_marginTopPercent="50%"
android:text="salary"
android:gravity="center"
app:layout_marginLeftPercent="68%"
android:textColor="@color/colorPrimary"
android:textSize="11dp"
android:textStyle="normal" />
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
</android.support.v7.widget.CardView>