android - Change Fragment's container height dynamically -
i want change container's height (which pageviewer
) fragment class on scroll event of listview
.
what have tried already :-
1.layoutparams
viewgroup.layoutparams params = view1.getlayoutparams(); params.height = mcontainerheight+ math.max(a,b); view1.requestlayout();
here view1
container.
2.getting container directly fragment class(by findviewbbyid) failed, because view in different(parent) layout , couldn't views different layout.
and many more tweaks based on above implementations.
i may doing wrong, tell want achieve. container's height should increase fill empty space between actionbar
, listview
. when scroll container height should increase.
what's happening . action bar moving container isnt.
i appreciate help.
edit 1 code
awesomecardfragment class
public class awesomecardfragment extends fragment { private int mactionbartitlecolor; private int mactionbarheight; private int mheaderheight; private int mminheadertranslation; private kenburnsview mheaderpicture; private imageview mheaderlogo; private view mheader; private view mplaceholderview; private acceleratedecelerateinterpolator msmoothinterpolator; private int mcontainerheight; private int mmincontainertranslation; private rectf mrect1 = new rectf(); private rectf mrect2 = new rectf(); private alphaforegroundcolorspan malphaforegroundcolorspan; private spannablestring mspannablestring; private typedvalue mtypedvalue = new typedvalue(); private static final string arg_position = "position"; // private int position; listview mlistview; viewpager vp; mainactivity ma; // button productbutton; // static string arg_position = "position"; private int position; // linearlayout rl; public static awesomecardfragment newinstance(int position) { awesomecardfragment f = new awesomecardfragment(); bundle b = new bundle(); b.putint(arg_position, position); f.setarguments(b); return f; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); position = getarguments().getint(arg_position); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { inflater.inflate(r.layout.activity_slide_main, container, false); framelayout fl = new framelayout(getactivity()); fl.setlayoutparams(params); final int margin = (int) typedvalue.applydimension( typedvalue.complex_unit_dip, 8, getresources() .getdisplaymetrics()); mlistview = new listview(getactivity()); params.setmargins(margin, margin, margin, margin); mlistview.setlayoutparams(params); mlistview.setlayoutparams(params); mlistview.setbackgroundresource(r.drawable.background_card); // test fl.addview(mlistview); msmoothinterpolator = new acceleratedecelerateinterpolator(); mheaderheight = getresources().getdimensionpixelsize( r.dimen.header_height); mminheadertranslation = -mheaderheight + getactionbarheight() + getactionbarheight(); mmincontainertranslation = mminheadertranslation + getactionbarheight() + getactionbarheight(); mheader = getactivity().findviewbyid(r.id.header); mheaderpicture = (kenburnsview) getactivity().findviewbyid( r.id.header_picture); mheaderpicture.setresourceids(r.drawable.picture0, r.drawable.picture1); mheaderlogo = (imageview) getactivity().findviewbyid(r.id.header_logo); mactionbartitlecolor = getresources().getcolor( r.color.actionbar_title_color); mspannablestring = new spannablestring( getstring(r.string.noboringactionbar_title)); malphaforegroundcolorspan = new alphaforegroundcolorspan( mactionbartitlecolor); mcontainerheight = container.getheight(); setuplistview(container); return fl; } private void setuplistview(final viewgroup view1) { arraylist<string> fakes = new arraylist<string>(); (int = 0; < 1000; i++) { fakes.add("entry " + i); } mplaceholderview = getactivity().getlayoutinflater().inflate( r.layout.view_header_placeholder, mlistview, false); // mplaceholderview = getactivity().getlayoutinflater().in mlistview.addheaderview(mplaceholderview); mlistview.setadapter(new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_1, fakes)); mlistview.setonscrolllistener(new abslistview.onscrolllistener() { @override public void onscrollstatechanged(abslistview view, int scrollstate) { } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { int scrolly = getscrolly(); viewgroup.layoutparams params = view1.getlayoutparams(); log.i("wtf", "container height"+mcontainerheight); params.height = mcontainerheight+ math.max(-scrolly, mminheadertranslation); log.i("wtf", "container height changed"+params.height); view1.requestlayout(); mheader.settranslationy(math.max(-scrolly, mminheadertranslation)); viewgroup.layoutparams param = (viewgroup.layoutparams) view1 .getlayoutparams(); if (param != null) { param.height = mcontainerheight + math.max(-scrolly, mminheadertranslation); view1.setlayoutparams(param); } // view1.settranslationy(math.max(-scrolly, // mminheadertranslation)); // header_logo --> actionbar icon float ratio = clamp(mheader.gettranslationy() / mminheadertranslation, 0.0f, 1.0f); interpolate(mheaderlogo, getactionbariconview(), msmoothinterpolator.getinterpolation(ratio)); settitlealpha(clamp(5.0f * ratio - 4.0f, 0.0f, 1.0f)); } }); } }
main xml class has container
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <framelayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="@dimen/header_height" > <com.flavienlaurent.notboringactionbar.kenburnsview android:id="@+id/header_picture" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/picture0" /> <imageview android:id="@+id/header_logo" android:layout_width="@dimen/header_logo_size" android:layout_height="@dimen/header_logo_size" android:layout_gravity="center" android:src="@drawable/ic_header_logo" /> <com.astuetz.pagerslidingtabstrip android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="48dip" android:layout_gravity="bottom" android:src="@drawable/background_tabs" /> </framelayout> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/colors" android:layout_below="@+id/header" tools:context=".mainactivity" /> <linearlayout android:id="@+id/colors" android:layout_width="match_parent" android:layout_height="48dip" android:layout_alignparentbottom="true" android:layout_marginbottom="8dip" android:layout_marginleft="4dip" android:layout_marginright="4dip" android:orientation="horizontal" > <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#ff666666" android:onclick="oncolorclicked" android:tag="#ff666666" /> <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#ff96aa39" android:onclick="oncolorclicked" android:tag="#ff96aa39" /> <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#ffc74b46" android:onclick="oncolorclicked" android:tag="#ffc74b46" /> <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#fff4842d" android:onclick="oncolorclicked" android:tag="#fff4842d" /> <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#ff3f9fe0" android:onclick="oncolorclicked" android:tag="#ff3f9fe0" /> <imageview android:layout_width="0dip" android:layout_height="match_parent" android:layout_margin="4dip" android:layout_weight="1" android:background="#ff5161bc" android:onclick="oncolorclicked" android:tag="#ff5161bc" /> </linearlayout>
you want control fragment dynamically, have use dialogfragment
instead fragment
.
have at: http://developer.android.com/reference/android/support/v4/app/dialogfragment.html http://developer.android.com/reference/android/app/dialogfragment.html
you can include layout paramters, control height & width dynamically.
Comments
Post a Comment