我想得到这个
这是我的xml布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="5dp"
app:cardCornerRadius="2dp"
android:layout_margin="2dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground">
<com.example.akash.music.view.SquareRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/img_button_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:background="?android:selectableItemBackground"
android:padding="4dp"
app:srcCompat="@drawable/ic_clear_black" />
<TextView
android:padding="4dp"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Hello"
android:textSize="@dimen/text_size_primary" />
<View
android:id="@+id/view"
android:layout_above="@+id/button_apply"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/colorBackground" />
<TextView
android:clickable="true"
android:padding="8dp"
android:textStyle="bold"
android:textSize="@dimen/text_size_primary"
android:id="@+id/button_apply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="APPLY"
android:gravity="center"
android:layout_alignParentBottom="true"
/>
</com.example.akash.music.view.SquareRelativeLayout>
</android.support.v7.widget.CardView>
这里是SquareRelativeLayout.class
public class SquareRelativeLayout extends RelativeLayout {
public SquareRelativeLayout(Context context) {
super(context);
}
public SquareRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(widthMeasureSpec,widthMeasureSpec);
}
}
问题是我无法将APPLY按钮对齐到SquareRelativeLayout的底部。如果我这样做,它就变得不可见了。