android - ScrollView with two views, first view filling screen -
i have scrollview linearlayout containing 2 views. first view should occupy full screen, second view off screen (but can scrolled to). achievable?
use code
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fillviewport="true" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" > <linearlayout android:id="@+id/linlayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <framelayout android:id="@+id/f1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#468432" > </framelayout> <framelayout android:id="@+id/f2" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ff8222" > </framelayout> </linearlayout> </scrollview>
and activity gose following
import android.os.bundle; import android.app.activity; import android.view.menu; import android.widget.linearlayout.layoutparams; import android.view.viewtreeobserver; import android.view.viewtreeobserver.ongloballayoutlistener; import android.widget.framelayout; import android.widget.linearlayout; public class mainactivity extends activity { linearlayout layout ; framelayout f1,f2; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); layout = (linearlayout)findviewbyid(r.id.linlayout); f1=(framelayout) findviewbyid(r.id.f1); f2=(framelayout) findviewbyid(r.id.f2); viewtreeobserver vto = layout.getviewtreeobserver(); vto.addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { layout.getviewtreeobserver().removeglobalonlayoutlistener(this); int width = layout.getmeasuredwidth(); int height = layout.getmeasuredheight(); f1.setlayoutparams(new layoutparams(width, height)); f2.setlayoutparams(new layoutparams(width, height)); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
Comments
Post a Comment