android - Layout woes with GridView rotation -
android - Layout woes with GridView rotation -
my aim have screen has top section textview, bottom section button, , middle section acts horizontal scrolling grid. using fragment gridview that's rotated 270, , rotating each item 90 has gotten me close i'm attempting achieve...however i'm struggling these layout issues can see in pic:
1) altering height of fragment cause 1st row of items partially clipped
2) width of gridview scroll right desired, visible right border of gridview not aligned right border of screen
3) i'd adjust space between top , bottom rows of grid, i'd expect altering height of gridview, adjusting height of gridview or fragment alters width
4) using typical combination of layout_weight 0dp set height isn't working, fragment not adjust it's height stated weight...also width shrinks too. view in attached pic, had add together fixed heights in dp in activity_my.xml
here's code...
activity_my.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightsum="1"> <textview android:id="@+id/top_text" android:layout_width="match_parent" android:layout_height="0dp" android:layout_margintop="0dp" android:lines="1" android:textsize="17sp" android:text="first text block" android:layout_gravity="center_horizontal" android:gravity="center_horizontal" android:layout_weight="0.50" /> <fragment android:layout_width="match_parent" android:layout_height="200dp" android:name="com.example.horizontalgrid2.mafragment" android:id="@+id/fragment" tools:layout="@layout/fragment_ma" android:background="#ff8c8c00" android:layout_weight="0.35"/> <button android:id="@+id/button_text" android:layout_width="match_parent" android:layout_height="30dp" android:layout_margintop="0dp" android:textsize="17sp" android:text="second text block" android:layout_gravity="center_horizontal" android:gravity="center_horizontal" android:layout_weight="0.15"/> </linearlayout>
fragment_ma.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <gridview android:id="@+id/tablegrid" android:layout_width="200dp" android:layout_height="wrap_content" android:background="#ffffff" android:horizontalspacing="1dp" android:verticalspacing="1dp" android:rotation="270" android:numcolumns="2" /> </linearlayout>
item_caller_grid.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="0dp" android:rotation="90"> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <imageview android:id="@+id/grid_item_image" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginleft="5dp" android:layout_marginstart="5dp" > </imageview> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:text="name" android:layout_below="@+id/grid_item_image"/> </relativelayout> </linearlayout>
myactivity.java
public class myactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_my); } }
mafragment.java
public class mafragment extends fragment { private view view; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view = inflater.inflate(r.layout.fragment_ma, container, false); gridview gridview = (gridview) view.findviewbyid(r.id.tablegrid); gridview.setadapter(new imageadapter(getactivity())); homecoming view; } }
imageadapter.java
public class imageadapter extends baseadapter { private context mcontext; public imageadapter(context c) { mcontext = c; } public int getcount() { homecoming mthumbids.length; } public object getitem(int position) { homecoming null; } public long getitemid(int position) { homecoming 0; } // create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) { imageview imageview; layoutinflater inflater = (layoutinflater) mcontext.getsystemservice(context.layout_inflater_service); view gridview; if (convertview == null) { gridview = new view(mcontext); gridview = inflater.inflate(r.layout.item_caller_grid, null); // set image based on selected text imageview = (imageview) gridview .findviewbyid(r.id.grid_item_image); imageview.setimageresource(mthumbids[position]); } else { gridview = (view) convertview; } homecoming gridview; } // references our images private integer[] mthumbids = { r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher, r.drawable.ic_launcher }; }
android gridview layout
Comments
Post a Comment