大佬教程收集整理的这篇文章主要介绍了android – 如何通过焦点在屏幕上调整两个片段的大小?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
可以通过动态改变碎片的重量吗?
或者有更好的方法来实现这一目标?
<android.support.v4.widget.DrawerLayout xmlns:android="http://scheR_305_11845@as.android.com/apk/res/android" xmlns:tools="http://scheR_305_11845@as.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="1.0"> <FrameLayout android:id="@+id/containerParent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".8"> <LinearLayout android:id="@+id/MainLinear" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:weightSum="1.0"> <FrameLayout android:id="@+id/fragment1" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight=".5"/> <FrameLayout android:id="@+id/fragment2" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight=".5"/> </LinearLayout> </FrameLayout> <FrameLayout android:id="@+id/fragment3" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight=".2"/> </LinearLayout> </FrameLayout> </android.support.v4.widget.DrawerLayout>
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,WEIGTH_HERE);
假设WEIGHT_HERE是一个浮点数(可能需要强制转换).
如果你想用一个按钮或其他东西,只需要做同样的事情
重量加上并添加:
Button b = new Button(this); param.weight= (float) 0.5 // 0.5f b.setLayoutParams(param);
但是这个方法会创建一个新的布局参数,所以如果你想保持一切只是做同样但不创建一个新的布局,通过获取它来编辑现有的布局:
LinearLayout.LayoutParams mLay = (LinearLayout.LayoutParams)myLay.getLayoutParams(); mLay.weight = (float) WEIGTH // WEIGHTf
以上是大佬教程为你收集整理的android – 如何通过焦点在屏幕上调整两个片段的大小?全部内容,希望文章能够帮你解决android – 如何通过焦点在屏幕上调整两个片段的大小?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。