简体   繁体   English

如何在父母布局的右上角添加两个浮动操作按钮(一半为内部布局,一半为外部),并在单击时显示

[英]How to add two floating action button on top-right of parrent layout (half insidelayout, and half outside), and show on click

i want to when user click on certain row of custom tableview to show two floating buttons on top-right position of parrent layout, but to be shown half in layout, and half outside layout. 我想当用户单击自定义表格视图的特定行以在父级布局的右上角位置显示两个浮动按钮时,在布局中显示一半,在布局外部显示一半。

Here is example: 这是示例:

在此处输入图片说明

Consider that bottom layout is in my case row of table view, 考虑到底部布局在我的情况下是表格视图的行,

Here is layout where i want to add fab: 这是我要添加晶圆厂的布局:

<?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>

Try this 尝试这个

<?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>

OUTPUT 输出值

在此处输入图片说明

Try this 尝试这个

<?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>

OUTPUT 输出值

在此处输入图片说明

You can try this code: 您可以尝试以下代码:

    <?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.

相关问题 如何在android中的一个布局上显示一半的按钮? - How to show a button half on one layout and half on another layout in android? 点击按钮的上半部分 - 不起作用? - Click on the top half of a button - doesn't work? 当CL的高度设置为wrap_Content时,为什么坐标布局(CL)隐藏浮动操作按钮的一半? - Why is Coordinate layout ( CL )hiding half of the floating action button when the height of CL is set to wrap_Content? 将按钮移动到半透明布局的右上角位置 - Move button to top-right position in translucent layout 如何将布局中心放在另一个布局的右上角? - How to place center of layout on top-right corner of another layout? 如何在滚动视图顶部添加浮动操作按钮 - How to add floating action button on top of scrollview 如何在动作栏上显示一半的图像 - How to display an image on action bar that is half outside 如何将布局按钮设计成一半一种颜色,另一半 - how to design layout button to be half one color, half other 我们如何将浮动操作按钮放在任何布局的顶部 - How we can put Floating action button on top of any layout 如图所示,如何将抽屉布局的关闭按钮朝向外侧弹出半部分 - How to place close button of drawer layout such a way that ejecting half portion towards outside as seen in picture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM