Android dialog can't fill screen width problem resolution

Source: Internet
Author: User


is to put the above custom layout into a dialog, the layout XML

<?xml version= "1.0" encoding= "UTF-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" 155DP "android:background=" @color/transparent "Android:paddingleft=" 0DP "android:paddingright=" 0DP "android:paddingbottom=" 10DP "android:paddingtop=" 0DP "&G    T <linearlayout android:id= "@+id/sharelayout" android:layout_width= "match_parent" android:layout_height= "WR Ap_content "android:background=" @drawable/share_dialog_bg "android:orientation=" vertical "android:pad ding= "0DP" android:layout_marginleft= "10DP" android:layout_marginright= "10DP" > <textview androi            D:id= "@+id/wxtext" android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:text= "Friends" android:textsize= "16sp" android:textcolor= "@color/head_text" Android          : gravity= "Center"  android:paddingtop= "12DP" android:paddingbottom= "12DP"/> <view android:layout_width= " Fill_parent "android:layout_height=" 1px "android:layout_alignparentbottom=" true "Android:            background= "#d1d1d1"/> <textview android:id= "@+id/wxfriend" android:layout_width= "Match_parent"            android:layout_height= "Wrap_content" android:text= "friend Circle" android:textsize= "16SP"            Android:textcolor= "@color/head_text" android:gravity= "center" android:paddingtop= "12DP" android:paddingbottom= "12DP"/> </LinearLayout> <textview android:id= "@+id/sharecancle" Android:la Yout_width= "Match_parent" android:layout_height= "Wrap_content" android:text= "Cancel" android:textsize= "16 SP "android:textcolor=" #FF4E17 "android:background=" @drawable/share_dialog_bg "Android:layout_margint op= "10DP" Android: layout_marginleft= "10DP" android:layout_marginright= "10DP" android:gravity= "center" android:paddingt op= "12DP" android:paddingbottom= "12DP" android:layout_below= "@id/sharelayout"/></relativelayout>

And then
View Dialogview = layoutinflater.from (activity). Inflate (r.layout.customsharelayout, NULL);
Sharedialog = new Dialog (activity, R.style.dialog_untran); Sharedialog.setcontentview (Dialogview); window window = Sharedialog.getwindow (); Windowmanager.layoutparams windowparams = Window.getattributes (); window.setgravity (Gravity.BOTTOM);  Rect rect = new rect ();  View view1 = Window.getdecorview ();  View1.getwindowvisibledisplayframe (rect);  Windowparams.height = densityutil.dip2px (activity, 155);  Windowparams.width = Settingutil.getdisplaywidthpixels ();  Window.setwindowanimations (r.style.animationdialog);  Window.setbackgrounddrawableresource (Android. r.color.transparent);  Window.setattributes ((android.view.WindowManager.LayoutParams) windowparams);  Sharedialog.show ();

Animation settings

<style name= "Animationdialog" >        <item name= "android:windowenteranimation" > @anim/custom_dialog_ enter</item>        <item name= "android:windowexitanimation" > @anim/custom_dialog_exit</item>    </style>

Custom_dialog_enter.xml

<?xml version= "1.0" encoding= "UTF-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:interpolator= "@android: Anim/decelerate_interpolator" >    <translate        android:duration= " @android: Integer/config_shortanimtime "        android:fromydelta=" 100%p "        android:toydelta=" 0 "/>    < Alpha        android:duration= "@android: Integer/config_shortanimtime"        android:fromalpha= "0.0"        android: Toalpha= "1.0"/></set>


The idea is to use dialog to set at the bottom, and the width and padding values are based on layout layouts.






Android dialog cannot fill screen width problem resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.