android - How to resolve problems with different screen sizes? -
i've designed interface when presented on device.
i found difference in size of device , size during presentation emulator.
what sizes suitable devices? see difference between 2 images:
package com.examp.swap_items; import java.util.arraylist; import java.util.list; import android.r.layout; import android.app.activity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.horizontalscrollview; import android.widget.tablelayout; import android.widget.tablerow; import android.widget.textview; import android.app.activity; import android.graphics.color; import android.os.bundle; import android.view.contextthemewrapper; import android.view.gravity; import android.widget.tablelayout; import android.widget.tablerow; import android.widget.tablerow.layoutparams; import android.widget.textview; import android.app.activity; public class mainactivity extends activity { private boolean showsummaries; private tablelayout summarytable; private tablelayout frozentable; private tablelayout contenttable; private button backbutton ; private horizontalscrollview hor; private textview recyclabletextview; private string[] allcolors ; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); color[] colors = {}; tablerow.layoutparams wrapwraptablerowparams = new tablerow.layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); int[] fixedcolumnwidths = new int[]{20,20, 20,20, 20, 20}; int[] scrollablecolumnwidths = new int[]{20,20, 20, 20, 20, 20}; int fixedrowheight = 50; int fixedheaderheight = 60; tablerow row = new tablerow(this); //header (fixed vertically) tablelayout header=(tablelayout)findviewbyid(r.id.table_header); row.setlayoutparams(wrapwraptablerowparams); row.setgravity(gravity.center); row.setbackgroundcolor(color.white); row.addview(maketablerowwithtext("col1",fixedcolumnwidths[0],fixedheaderheight)); row.addview(maketablerowwithtext("col2",fixedcolumnwidths[1],fixedheaderheight)); row.addview(maketablerowwithtext("col3",fixedcolumnwidths[2],fixedheaderheight)); row.addview(maketablerowwithtext("col4",fixedcolumnwidths[3],fixedheaderheight)); row.addview(maketablerowwithtext("col5",fixedcolumnwidths[4],fixedheaderheight)); // row.addview(maketablerowwithtext("col6", fixedcolumnwidths[5],fixedheaderheight)); header.addview(row); hor = (horizontalscrollview)findviewbyid(r.id.scroller); hor.postdelayed(new runnable(){ public void run() { hor.fullscroll(horizontalscrollview.focus_right); }},1l); tablelayout fixedcolumn = (tablelayout) findviewbyid(r.id.scrollable_part2); //rest of table (within scroll view) tablelayout scrollablepart = (tablelayout)findviewbyid(r.id.scrollable_part); for(int = 0; < 10; i++) { textview fixedview = maketablerowwithtext("fixed number " + i, scrollablecolumnwidths[0], fixedrowheight); fixedview.setbackgroundcolor(color.green); fixedview.setgravity(gravity.right); fixedcolumn.addview(fixedview); row = new tablerow(this); row.setlayoutparams(wrapwraptablerowparams); row.setgravity(gravity.left); if(i==1)row.setbackgroundcolor(color.red); if(i==2)row.setbackgroundcolor(color.magenta); if(i==3)row.setbackgroundcolor(color.yellow); if(i==4)row.setbackgroundcolor(color.gray); if(i==5)row.setbackgroundcolor(color.ltgray); if(i==6)row.setbackgroundcolor(color.white); if(i==7)row.setbackgroundcolor(color.cyan); if(i==8)row.setbackgroundcolor(color.transparent); if(i==9)row.setbackgroundcolor(color.magenta); row.addview(maketablerowwithtext("scroll 1", scrollablecolumnwidths[1], fixedrowheight)); row.addview(maketablerowwithtext("scroll 2", scrollablecolumnwidths[1], fixedrowheight)); row.addview(maketablerowwithtext("scroll 3", scrollablecolumnwidths[2], fixedrowheight)); row.addview(maketablerowwithtext("scroll 4", scrollablecolumnwidths[3], fixedrowheight)); row.addview(maketablerowwithtext("scroll 5", scrollablecolumnwidths[4], fixedrowheight)); row.addview(maketablerowwithtext("scroll 6", scrollablecolumnwidths[5], fixedrowheight)); scrollablepart.addview(row); } } public textview maketablerowwithtext(string text, int widthinpercentofscreenwidth, int fixedheightinpixels) { int screenwidth = getresources().getdisplaymetrics().widthpixels; recyclabletextview = new textview(this); recyclabletextview.settext(text); recyclabletextview.settextcolor(color.black); recyclabletextview.settextsize(20); recyclabletextview.setwidth(widthinpercentofscreenwidth * screenwidth / 100); recyclabletextview.setheight(fixedheightinpixels); return recyclabletextview; } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
and xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right" android:id="@+id/fillable_area"> <tablelayout android:gravity="right" android:id="@+id/table_header" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <scrollview android:layout_width="fill_parent" android:layout_height="wrap_content"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <horizontalscrollview android:id="@+id/scroller" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"> <tablelayout android:id="@+id/scrollable_part" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </horizontalscrollview> <tablelayout android:id="@+id/scrollable_part2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </linearlayout> </scrollview> </linearlayout>
you assign weights instead of gravity? i'm not sure. maybe match_parent instead of fill_parent? not sure, still noob making apps , stuff. please vote.
Comments
Post a Comment