首页 > 解决方案 > 如何忽略或禁用线性布局

问题描述

首先,我想做一个底部弹出,但我不知道如何忽略布局。我只想显示灰色布局。我正在尝试使其对白色布局透明,但它不起作用。我想我必须使用一些代码来忽略或删除它。我使用不可见的,这将使所有布局不可见。

这是我制作弹出窗口的代码

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_account, container, false);

    backbutton1 = (ImageView) rootView.findViewById(R.id.backbutton1);
    btnprofile = (Button) rootView.findViewById(R.id.btnprofile);
    backbutton1.setOnClickListener(onClickListener);
    btnprofile.setOnClickListener(onClickListener);

    return  rootView;

}

private View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if(view == backbutton1) {
            startActivity(new Intent(getActivity().getApplicationContext(), sidemenu.class));
            getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
        }if(view == btnprofile){

            Bottom_sheet bottom_sheet = new Bottom_sheet();
            bottom_sheet.show(getFragmentManager(), "examplebottomsheet");

        }
    }
};

Bottom_Sheet 类:

   public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.popout_chooseimage, container, false);

    Button btnCancel = (Button) view.findViewById(R.id.buttonCancel);
    Button btnRemove = (Button) view.findViewById(R.id.buttonRemove);
    Button btnTake = (Button) view.findViewById(R.id.buttonTake);
    Button btnLibrary = (Button) view.findViewById(R.id.buttonLibrary);

    LinearLayout linear = (LinearLayout) view.findViewById(R.id.bottom_layout);
    linear.setBackgroundResource(0);

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    return view;
}

布局:

 <LinearLayout
    android:layout_width="800px"
    android:layout_height="400px"
    android:orientation="vertical"
    android:background="@drawable/button_popout"
    android:layout_marginBottom="10dp"
    android:layout_gravity="center">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="100px"
        android:background="@drawable/bottom_line">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change Profile Photo"
            android:fontFamily="@font/seguisb"
            android:textColor="@color/Black"
            android:textSize="30px"
            android:layout_centerInParent="true"/>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100px"
        android:background="@drawable/bottom_line">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Remove Current Photo"
            android:textColor="@color/red"
            android:fontFamily="@font/segoeui"
            android:layout_centerInParent="true"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buttonRemove"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100px"
        android:background="@drawable/bottom_line">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Take A Photo"
            android:textColor="@color/active_dots"
            android:fontFamily="@font/segoeui"
            android:layout_centerInParent="true"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buttonTake"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100px">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Choose From Library"
            android:textColor="@color/active_dots"
            android:fontFamily="@font/segoeui"
            android:layout_centerInParent="true"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buttonLibrary"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="800px"
    android:layout_height="wrap_content"
    android:background="@drawable/button_popout"
    android:layout_gravity="center">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100px">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel"
            android:textSize="40px"
            android:fontFamily="@font/seguibl"
            android:layout_centerInParent="true"/>

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buttonCancel"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

</LinearLayout>

输出将显示

在此处输入图像描述

标签: javaandroidxml

解决方案


推荐阅读