Android – removes additional properties from the top of the custom dialog box

I created a custom dialog box. I dynamically put views into it through relativelayout. Every time the dialog box is displayed, it will display all my sub views, but there is some space at the top that I can't explain. I assume this is reserved for the "title" of the dialog box (I won't have it) Is there any way to delete the space and let my custom dialog box wrap only the content I am putting in?

This is the XML of the layout:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <RelativeLayout
     android:id="@+id/handlay"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" />  
</LinearLayout>

By the way, I tried to make the relative layout the parent node, and the results were the same

This is the. Java. Of the custom dialog box

public class HandResults extends Dialog implements DialogInterface {
    HandResults hr;
    Timer myTimer;
    RelativeLayout handrl;


    // constructor sets the layout view to handresult layout
    public HandResults(Context context) {
        super(context);
        setContentView(R.layout.handresults);
        hr = this;

    }

    // create a timer to remove the dialog after 3 seconds
    public void showHands(){
        this.show();
        myTimer = null;
        myTimer = new Timer();
        myTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                hr.cancel(); 
            }
        }, 3000);

    }
}

Here is how I will invoke the dialog box:

HandResults mhr = new HandResults(this);
mhr.showHands();

No matter what I do or how I change the layout file, I always have a buffer at the top. How can I get rid of it?

resolvent:

Put this code into the class constructor or oncreate() method:

    requestWindowFeature(Window.FEATURE_NO_TITLE);

It must be before calling the setcontentview method

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>