Http://blog.sina.com.cn/s/blog_9996c67e0101euwd.html recently in a project to achieve screen adaptation tablet and mobile phone and other models, and the egg pain of the artist gave a set of pictures, and these drawings are in 1280x 800 of the flat can be layout normal, so there is no way, only their own step by step to write, finally let me in degrees Niang and Gu brother found a similar solution, now my own implementation of the method paste out: First I have a activity_index.xml file:
<Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "@drawable/ergetiandi_back1" > Android:id= "@+id/rel_title" android:layout_width= "fill_parent" android:layout_height= "Wrap_conte NT "android:layout_alignparenttop=" true "> android:id=" @+id/er_ge_tian_di "Android : layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "60dip" android:layout_margintop= "80dip" android:background= "@drawable/select_go_back_press"/> Android:id= "@+id/upper_paper" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "android:layout_marginleft=" 620dip "android:layout_margintop=" 50dip "Android: background= "@drawable/select_pager_up_press"/> android:id= "@+id/next_paper" Android:layo Ut_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "620dip" Android:layout_margintop= "50dip" android:background= "@drawable/select_pager_down_press"/> android:id= "@+i D/song "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android: layout_marginleft= "160dip" android:layout_margintop= "160dip" android:background= "@drawable/select_so Ng_press "/> android:id=" @+id/accompany "android:layout_width=" Wrap_content "a ndroid:layout_height= "Wrap_content" android:layout_alignbottom= "@+id/song" Android:layout_marginleft = "21DP" android:layout_torightof= "@+id/song" android:background= "@drawable/select_accompany_press" /> android:id= "@+id/gridview1" android:layout_width= "Fill_parent" Android:layout_h eight= "450dip" android:layout_below= "@+id/rel_title" android:layout_margintop= "60dip" Android:numcolu mns= "5" >
<Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "@drawable/ergetiandi_back1" > Android:id= "@+id/rel_title" android:layout_width= "fill_parent" android:layout_height= "Wrap_conte NT "android:layout_alignparenttop=" true "> android:id=" @+id/er_ge_tian_di "Android : layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "60dip" android:layout_margintop= "80dip" android:background= "@drawable/select_go_back_press"/> Android:id= "@+id/upper_paper" android:layout_width= "Wrap_content" android:layout_height= "W Rap_content "android:layout_marginleft=" 620dip "android:layout_margintop=" 50dip "Android: background= "@drawable/select_pager_up_press"/> android:id= "@+id/next_paper" Android:layo Ut_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_marginleft= "620dip" Android:layout_margintop= "50dip" android:background= "@drawable/select_pager_down_press"/> android:id= "@+i D/song "android:layout_width=" wrap_content "android:layout_height=" Wrap_content "Android: layout_marginleft= "160dip" android:layout_margintop= "160dip" android:background= "@drawable/select_so Ng_press "/> android:id=" @+id/accompany "android:layout_width=" Wrap_content "a ndroid:layout_height= "Wrap_content" android:layout_alignbottom= "@+id/song" Android:layout_marginleft = "21DP" android:layout_torightof= "@+id/song" android:background= "@drawable/select_accompany_press" /> android:id= "@+id/gridview1" android:layout_width= "Fill_parent" Android:layout_h eight= "450dip" android:layout_below= "@+id/rel_title" android:layout_margintop= "60dip" Android:numcolu mns= "5" >
Then in the class file corresponding to fill in the XML corresponding value is the line:
Private voidgetfindviews () {Upper_paper=(Button) Findviewbyid (r.id.upper_paper); Next_paper=(Button) Findviewbyid (r.id.next_paper); Btnback= (Button) This. Findviewbyid (R.id.er_ge_tian_di); Btnsong= (Button) This. Findviewbyid (R.id.song); Btnaccompany= (Button) This. Findviewbyid (R.id.accompany); Relativelayout.layoutparams Er_ge_tian_diparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (60 *config.height_rate)); Er_ge_tian_diparams.leftmargin= (int) (60 *config.with_rate); Er_ge_tian_diparams.topmargin= (int) (80 *config.height_rate); Btnback.setlayoutparams (Er_ge_tian_diparams); Relativelayout.layoutparams Next_paperparams=NewRelativelayout.layoutparams ((int) (Config.with_rate *), (int) (55 *config.height_rate)); Next_paperparams.leftmargin=(int) (620 *config.with_rate); Next_paperparams.topmargin=(int) (50 *config.height_rate); Next_paper.setlayoutparams (Next_paperparams); Relativelayout.layoutparams Upper_paperparams=NewRelativelayout.layoutparams ((int) (Config.with_rate *), (int) (55 *config.height_rate)); Upper_paperparams.leftmargin=(int) (620 *config.with_rate); Upper_paperparams.topmargin=(int) (50 *config.height_rate); Upper_paper.setlayoutparams (Upper_paperparams); Relativelayout.layoutparams Songparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (30 *config.height_rate)); Songparams.leftmargin=(int) (160 *config.with_rate); Songparams.topmargin=(int) (160 *config.height_rate); Btnsong.setlayoutparams (Songparams); Relativelayout.layoutparams Accompanyparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (30 *config.height_rate)); Accompanyparams.leftmargin=(int) (21 *config.with_rate); Accompanyparams.addrule (relativelayout.right_of, R.id.song); Accompanyparams.addrule ( Relativelayout.align_bottom, R.id.song); Btnaccompany.setlayoutparams (Accompanyparams); Relativelayout.layoutparams Gridview1params=NewRelativelayout.layoutparams (RelativeLayout.LayoutParams.FILL_PARENT, (int) (450 *config.height_rate)); Gridview1params.topmargin=(int) (60 *config.height_rate); Gridview1params.addrule (Relativelayout.below, r.id.rel_title); mGridView.setLayoutParams (gridview1params);
Private voidgetfindviews () {Upper_paper=(Button) Findviewbyid (r.id.upper_paper); Next_paper=(Button) Findviewbyid (r.id.next_paper); Btnback= (Button) This. Findviewbyid (R.id.er_ge_tian_di); Btnsong= (Button) This. Findviewbyid (R.id.song); Btnaccompany= (Button) This. Findviewbyid (R.id.accompany); Relativelayout.layoutparams Er_ge_tian_diparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (60 *config.height_rate)); Er_ge_tian_diparams.leftmargin= (int) (60 *config.with_rate); Er_ge_tian_diparams.topmargin= (int) (80 *config.height_rate); Btnback.setlayoutparams (Er_ge_tian_diparams); Relativelayout.layoutparams Next_paperparams=NewRelativelayout.layoutparams ((int) (Config.with_rate *), (int) (55 *config.height_rate)); Next_paperparams.leftmargin=(int) (620 *config.with_rate); Next_paperparams.topmargin=(int) (50 *config.height_rate); Next_paper.setlayoutparams (Next_paperparams); Relativelayout.layoutparams Upper_paperparams=NewRelativelayout.layoutparams ((int) (Config.with_rate *), (int) (55 *config.height_rate)); Upper_paperparams.leftmargin=(int) (620 *config.with_rate); Upper_paperparams.topmargin=(int) (50 *config.height_rate); Upper_paper.setlayoutparams (Upper_paperparams); Relativelayout.layoutparams Songparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (30 *config.height_rate)); Songparams.leftmargin=(int) (160 *config.with_rate); Songparams.topmargin=(int) (160 *config.height_rate); Btnsong.setlayoutparams (Songparams); Relativelayout.layoutparams Accompanyparams=NewRelativelayout.layoutparams ((int) (Config.with_rate), (int) (30 *config.height_rate)); Accompanyparams.leftmargin=(int) (21 *config.with_rate); Accompanyparams.addrule (relativelayout.right_of, R.id.song); Accompanyparams.addrule ( Relativelayout.align_bottom, R.id.song); Btnaccompany.setlayoutparams (Accompanyparams); Relativelayout.layoutparams Gridview1params=NewRelativelayout.layoutparams (RelativeLayout.LayoutParams.FILL_PARENT, (int) (450 *config.height_rate)); Gridview1params.topmargin=(int) (60 *config.height_rate); Gridview1params.addrule (Relativelayout.below, r.id.rel_title); mGridView.setLayoutParams (gridview1params);