android - CoordinatorLayout / RelativeLayout issue within a ViewSwitcher -
this follow question of one: coordinator layout , relative layout issue
i have issue when have coordinatorlayout
relativelayout
within viewswitcher
following example:
<?xml version="1.0" encoding="utf-8"?> <viewswitcher xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/switcher"> <!--first switcher view / splash screen--> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/coloraccent"> </relativelayout> <!--second switcher view--> <android.support.design.widget.coordinatorlayout 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" android:fitssystemwindows="true" tools:context="com.example.test"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" app:popuptheme="@style/apptheme.popupoverlay"/> </android.support.design.widget.appbarlayout> <!--as @linx64 suggested in previous question--> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="70dp" android:layout_alignparentbottom="true" android:background="@color/coloraccent" android:focusable="true" android:focusableintouchmode="true" android:text="text" android:textcolor="@android:color/white" /> </relativelayout> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email"/> </android.support.design.widget.coordinatorlayout> </viewswitcher>
and in activity
:
final viewswitcher switcher = (viewswitcher) findviewbyid(r.id.switcher); //if use switcher.shownext() activity starts, works fine. new countdowntimer(1500, 1500) { @override public void ontick(long millisuntilfinished) {} @override public void onfinish() { switcher.shownext(); } }.start();
result: (screenshot taken moto g
android
5.1)
as can see, button isn't @ bottom of screen , it's been cropped.
expected result:
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest package="com.example.test" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity" android:label="@string/app_name" android:theme="@style/apptheme.noactionbar"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> </activity> </application> </manifest>
styles
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <!-- customize theme here. --> <item name="colorprimary">@color/colorprimary</item> <item name="colorprimarydark">@color/colorprimarydark</item> <item name="coloraccent">@color/coloraccent</item> </style> <style name="apptheme.noactionbar"> <item name="windowactionbar">false</item> <item name="windownotitle">true</item> </style> <style name="apptheme.appbaroverlay" parent="themeoverlay.appcompat.dark.actionbar"/> <style name="apptheme.popupoverlay" parent="themeoverlay.appcompat.light"/> </resources>
worked me runonuithread(new runnable()
after working on
public class mainactivity extends appcompatactivity { public handler mhandler; private viewswitcher switcher; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); switcher = (viewswitcher) findviewbyid(r.id.switcher); mhandler = new handler(); runonuithread(new runnable() { @override public void run() { // todo auto-generated method stub try { thread.sleep(5000); // every 5 seconds mhandler.post(new runnable() { @override public void run() { // todo auto-generated method stub switcher.shownext(); } }); } catch (exception e) { // todo: handle exception } } }); } }
and of course, xml
:
<!--as @linx64 suggested in previous question--> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="70dp" android:layout_alignparentbottom="true" android:background="@color/coloraccent" android:focusable="true" android:focusableintouchmode="true" android:text="text" android:textcolor="@android:color/white" /> </relativelayout>
Comments
Post a Comment