编程改变相对布局 [英] Changing relative layout programmatically
本文介绍了编程改变相对布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经相对布局即的main.xml 这是我设置如下。但现在我已经把厂景对视图2是宽度= 200dp和高度= 100dp ,使视图2将大单和厂景将在它小的。
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
}
的main.xml
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /根
机器人:layout_width =match_parent
机器人:layout_height =match_parent> < RelativeLayout的
机器人:ID =@ + ID / mainPanel中
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_above =@ ID / panel_bottom
机器人:layout_gravity =CENTER_HORIZONTAL> < com.proj.demo.view1
机器人:ID =@ + ID /表
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_alignWithParentIfMissing =真
机器人:layout_centerInParent =真
机器人:layout_toLeftOf =@ + ID / panel_quick_buttons
/> < com.proj.demo.view2
机器人:ID =@ + ID / Sheet2的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_alignWithParentIfMissing =真
机器人:layout_centerInParent =真
机器人:layout_toLeftOf =@ + ID / panel_quick_buttons
/>< / RelativeLayout的>
< / RelativeLayout的>
解决方案
那你想达到什么目的?如果你只是想改变宽度和唤起注意比:
RelativeLayout的RL =(RelativeLayout的)findViewById(R.id.yourId);
。rl.getLayoutParams()高度= 100;
。rl.getLayoutParams()宽= 100;
I've relative layout i.e. main.xml which I set as follows. But now I've to put view1 on view2 with width=200dp and height =100dp, so that view2 will be large one and view1 will be small one on it.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/MainPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/panel_bottom"
android:layout_gravity="center_horizontal" >
<com.proj.demo.view1
android:id="@+id/sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignWithParentIfMissing="true"
android:layout_centerInParent="true"
android:layout_toLeftOf="@+id/panel_quick_buttons"
/>
<com.proj.demo.view2
android:id="@+id/sheet2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignWithParentIfMissing="true"
android:layout_centerInParent="true"
android:layout_toLeftOf="@+id/panel_quick_buttons"
/>
</RelativeLayout>
</RelativeLayout>
解决方案
What do you want to achieve? If you just want to change width and heigh than:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId);
rl.getLayoutParams().height = 100;
rl.getLayoutParams().width = 100;
这篇关于编程改变相对布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文