如何管理相对布局动态控制? [英] How to manage control in relative layout Dynamically?

查看:170
本文介绍了如何管理相对布局动态控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个设计问题相对布局。其实我想这种类型的OUT输出。

这一切应该是动态的。
我从激励
<一href=\"http://stackoverflow.com/questions/11736658/android-heterogeneous-gridview-like-pinterest\">Android异构gridview的像Pinterest的?

我想添加两个按钮一样 - 不喜欢在右上角。我能做到这一点的布局完美,但如何添加两个按钮动态,我不知道。

按我的思维相对布局仅仅是实现这一目标的方式输出。如果有任何替代解决方案,请分享。

请指引我它的真正AP preciated。

感谢分析我的问题。


解决方案

  

我想添加像两个按钮 - 不喜欢在右上角。我可以
  该布局完美,但如何动态地添加这两个按钮
  我不知道。
  按我的思维相对布局仅仅是实现这一目标的方式输出。
  如果有任何替代解决方案,请分享。


RelativeLayout的不是做单一的方式,但它是这样做的最有效方法。你可以,例如包裹的ImageView 的FrameLayout ,也把那些二两按钮在一个水平的LinearLayout 。然后,您将地方的LinearLayout 的FrameLayout 使用 layout_gravity 设置为底部|权。但 RelativeLayout的是去,因为你会避免使用包装容器和两个之间的一个额外的布线方式按钮 。对于 RelativeLayout的你必须在布局的末尾:

 &LT;&RelativeLayout的GT;
   &LT; ImageView的宽度|高度= FILL_PARENT /&GT;
   &LT;按键宽度|高度= WRAP_CONTENT的Andr​​oid =@ + ID /不喜欢
         机器人:layout_alignParentRight =真
         机器人:layout_alignParentBottom =真/&GT;
   &LT;按键宽度|高度= WRAP_CONTENT的Andr​​oid =@ + ID /像
         机器人:layout_toLeftOf =@ ID /不喜欢
         机器人:layout_alignParentBottom =真/&GT;
&LT; / RelativeLayout的&GT;

如果您添加按钮在code,你会设置 RelativeLayout.LayoutParams 按钮,并设置相应的规则,在XML布局那些的LayoutParams

One designing issue in relative layout. Actually i want this type out output.

This all should be dynamically. I inspire from Android heterogeneous gridview like pinterest?

i want to add two buttons like - Dislike in right corner. i can do that layout perfectly but how to add that two button dynamically that i don't know.

As per my thinking relative layout is only way to achieve this output. if there are any alternative solution please share it.

Please guide me it's truly appreciated.

Thanks for analyze my question.

解决方案

i want to add two buttons like - Dislike in right corner. i can do that layout perfectly but how to add that two button dynamically that i don't know. As per my thinking relative layout is only way to achieve this output. if there are any alternative solution please share it.

RelativeLayout is not the single way to do it but it's the most efficient way to do it. You could, for example wrap the ImageView in a FrameLayout and also put those two two Buttons in a horizontal LinearLayout. You'll then place that LinearLayout in the FrameLayout using layout_gravity set to bottom|right. But RelativeLayout is the way to go because you'll avoid using an extra layout between the wrapper container and the two Buttons. For a RelativeLayout you'll have at the end of the layout:

<RelativeLayout>
   <ImageView width|height=fill_parent />
   <Button width|height=wrap_content android="@+id/dislike"  
         android:layout_alignParentRight="true"   
         android:layout_alignParentBottom="true" />


   <Button width|height=wrap_content android="@+id/like"  
         android:layout_toLeftOf="@id/dislike"   
         android:layout_alignParentBottom="true" />
</RelativeLayout>

If you add the Buttons in code you would set RelativeLayout.LayoutParams for the Buttons and also set the appropriate rules as in the xml layout for those LayoutParams.

这篇关于如何管理相对布局动态控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆