簡體   English   中英

如何在父母布局的右上角添加兩個浮動操作按鈕(一半為內部布局,一半為外部),並在單擊時顯示

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM