scroll view disable only in portrait mode in android -
scroll view disable only in portrait mode in android -
i had scrollview in xml scroll view should work in landscape mode of phone not in portrait mode of phone.can possible , if possible should go xml file or through programmatically.if code require please inquire me.thanks
here xml file(portrait mode):
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/scrollview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#1e90ff" tools:context=".homeactivity" android:scrollbars="none" > <linearlayout android:id="@+id/layout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#a9a9a9" android:orientation="vertical" > <button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginleft="1dp" android:background="@drawable/my_tauky_button_img" /> <button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginleft="1dp" android:background="@drawable/explore_button_img" android:text="" /> <button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginleft="1dp" android:background="@drawable/create_tauky_button_img" /> <button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginleft="1dp" android:background="@drawable/my_blauky_button_img" /> <button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="match_parent" android:background="@drawable/profile_button_img" /> </linearlayout> </scrollview>
your simplest solution check:
getresources().getconfiguration().orientation;
in oncreate()
, disable scrollview
if orientation portrait
. see reference here: http://developer.android.com/reference/android/content/res/configuration.html#orientation
it works because default activities
restarted on configuration changes (including alter in orientation), don't have hear event.
simply modify oncreate()
:
@override protected void oncreate(bundle savedstate) { super.oncreate(savedstate); setcontentview(r.layout.activity_layout); // disable scrollview in portrait mode if (getresources().getconfiguration().orientation == configuration.orientation_portrait) { scrollview scrollview = (scrollview)findviewbyid(r.id.scrollview1); scrollview.setenabled(false); } }
where activity_layout
layout file name (without .xml
extension). that's it!
android
Comments
Post a Comment