[英]How to show a button half on one layout and half on another layout in android?
[英]How to add two floating action button on top-right of parrent layout (half insidelayout, and half outside), and show on click
我想当用户单击自定义表格视图的特定行以在父级布局的右上角位置显示两个浮动按钮时,在布局中显示一半,在布局外部显示一半。
这是示例:
考虑到底部布局在我的情况下是表格视图的行,
这是我要添加晶圆厂的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainAddEditIcons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/tvLAyout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tvRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:paddingLeft="20dp"
android:textColor="@color/black" />
</LinearLayout>
</LinearLayout>
尝试这个
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainAddEditIcons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/tvLAyout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:background="@color/colorblueLight"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
android:text="NIlu" />
</LinearLayout>
<LinearLayout
android:id="@+id/tvLAyout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent"
android:orientation="vertical" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/l_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:clickable="true"
android:src="@drawable/floating_add"
app:backgroundTint="@color/colorOrange"
app:fabSize="normal"
app:layout_anchor="@id/tvLAyout1"
app:layout_anchorGravity="bottom|right" />
</android.support.design.widget.CoordinatorLayout>
输出值
尝试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/nilu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:orientation="vertical"
android:paddingBottom="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
<LinearLayout
android:id="@+id/nilu2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/nilu"
android:background="@color/colorGray"
android:orientation="vertical"
android:paddingTop="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="NILU" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/nilu"
android:layout_marginTop="-15dp"
android:orientation="horizontal">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="16dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:src="@mipmap/ic_launcher_round"
app:elevation="2dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
输出值
您可以尝试以下代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E0E0E0">
<RelativeLayout
android:id="@+id/top_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:alpha="1.0"
android:scaleType="centerCrop"
tools:src="@drawable/food_1" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/gradient_up" />
<!-- Back button -->
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_show_rating_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/top_card"
android:layout_alignParentRight="true"
android:layout_marginBottom="-28dp"
android:layout_marginRight="16dp"
app:srcCompat="@drawable/ic_add_white_24px" />
<!-- Ratings -->
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top_card"
android:background="@android:color/transparent"
android:clipToPadding="false"
android:paddingBottom="16dp"
android:paddingTop="28dp"
android:visibility="gone"
tools:listitem="@layout/item_rating" />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.