Thursday, October 10, 2013

Display scrollview button click event

I have images under scrollview. I have a button to click event. When i click the button i need to display scrollview. But when i install app the scrollview is automatically displaying bottom of the page.

code:

<RelativeLayout 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: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=".Scroll" >    <HorizontalScrollView        android:id="@+id/scrl"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginTop="250dp" >        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:orientation="horizontal" >            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access"                />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access1"                 />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access2"                />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access3"                 />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access4"                />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access5"                 />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access6"                 />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access7"                 />            <Button                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@drawable/access8"                 />        </LinearLayout>    </HorizontalScrollView>    <Button         android:id="@+id/btn"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/>        <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>

Button click:

Button btn=(Button)findViewById(R.id.btn);btn.setOnClickListener(new OnClickListener(){            @Override            public void onClick(View v) {                // TODO Auto-generated method stub    HorizontalScorllView    srl=(HorizontalScrollView)findViewById(R.id.scrl);                  }        });

By default set visiblity of android:id=”@+id/scrl” as invisible in xml.
After click on button
HorizontalScorllView srl=(HorizontalScrollView)findViewById(R.id.scrl);
set visiblity of srl as visble.

No comments:

Post a Comment