以编程方式设置android布局权重 [英] android Layout weight programmatically
本文介绍了以编程方式设置android布局权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经对布局xml上的layout_weight进行了硬编码.但是现在我想从Java代码中给出layout_weight和weightSum.
i have hard-coded the layout_weight on layout xml.but now i want to give the layout_weight and weightSum from java code.
我们该如何在课堂上做到这一点?
How we do that from our class?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="25" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:background="#F51215"
android:paddingLeft="5dip"
android:text="5" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20"
android:background="#1AC92B"
android:paddingLeft="5dip"
android:text="20" />
</LinearLayout>
推荐答案
//set as like this below for different view set different float value.
myview.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,5f));
这篇关于以编程方式设置android布局权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文