从膨胀的布局中删除黑色边框 [英] remove black border from inflated layout

查看:105
本文介绍了从膨胀的布局中删除黑色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PopupWindow,它工作正常,但是问题是在放大显示有黑色边框的布局视图之后.

I am using PopupWindow, which is working fine, but the problem is after inflating the layout view that is shown with black border.

final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);

pop_up_window_menu_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/solid_white"
android:orientation="vertical" >

<TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:text="SAVE"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="@color/black"
        android:textSize="@dimen/txt_size_sliding_list" />

我尝试使用popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))删除边框,但是问题仍然相同.

I've tried to remove border by using popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)), but problem is still same.

有人可以告诉我如何删除不需要的黑色边框吗?

Can anyone tell me how to remove unwanted black border?

推荐答案

我的弹出窗口周围没有看到任何边框,但是我将它们设置为与您稍有不同.希望这会为您指明正确的方向.

I don't see any border around my popup windows, but I do set them up slightly different than you. Hopefully this points you in the right direction.

popup_view.xml

popup_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#f5f5f5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <Button
        android:id="@+id/btn_close"
        android:text="Close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

activity_main.xml

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:id="@+id/main_view"
                tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_popup"
        android:text="Popup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/txt_text"
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

MainActivity.java

MainActivity.java

public class MainActivity extends ActionBarActivity implements View.OnClickListener {

    View popupView;
    Button btnPopup;
    Button btnClose;
    PopupWindow popupWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
        btnClose = (Button) popupView.findViewById(R.id.btn_close);
        btnClose.setOnClickListener(this);

        popupWindow = new PopupWindow(popupView,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);

        btnPopup = (Button) findViewById(R.id.btn_popup);
        btnPopup.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_popup) {
            popupWindow.showAtLocation(findViewById(R.id.main_view), Gravity.NO_GRAVITY, 100, 200);
            //popupWindow.showAsDropDown(btnPopup, 10, 10);
        } else if (v.getId() == R.id.btn_close) {
            popupWindow.dismiss();
        }
    }
}

这篇关于从膨胀的布局中删除黑色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆