layout_anchor和app:layout_anchorGravity不在片段中工作

时间:2016-12-06 10:26:17

标签: android android-fragments android-viewpager fragment

我在片段的布局文件中使用了CoordinateLayout。我需要在两个布局之间使用ImageButton。我从[this] [1]回答中得到了示例代码。

但是当我把我的片段放在viewpager中时它无法正常工作,这是我的代码。



<img src="https://i.stack.imgur.com/wZasU.png"/>
&#13;
&#13;
&#13;

 public class Profile extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View Rootview =inflater.inflate(R.layout.tab_profile_fragment, container, false);
        CircleImageView fab = (CircleImageView) Rootview.findViewById(R.id.fab);

        return Rootview;
    }
}

Xml代码:

<android.support.design.widget.CoordinatorLayout
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">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/aasda"
    android:weightSum="1"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/viewA"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".3"

        android:orientation="horizontal">

    </LinearLayout>


    <RelativeLayout
        android:id="@+id/viewB"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".7"
        android:background="@color/white"
        android:gravity="top"
        android:orientation="vertical">
    <android.support.v7.widget.CardView
        android:id="@+id/tab_profile_cardviewname"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        >

    </android.support.v7.widget.CardView>
    </RelativeLayout>
</LinearLayout>

<com.citizenassistant.View.Componnent.CircleImageView
    android:id="@+id/fab"
    android:layout_width="90dp"
    android:layout_height="90dp"
    android:clickable="true"
    android:src="@color/blue"
    android:backgroundTint="@color/white"
    app:layout_anchor="@id/tab_profile_cardviewname"
    app:layout_anchorGravity="top|center_horizontal"/>

0 个答案:

没有答案