当前位置: 代码迷 >> Android >> 有没有或许这样布局:比如TextView的位置距屏幕左边4分之一
  详细解决方案

有没有或许这样布局:比如TextView的位置距屏幕左边4分之一

热度:70   发布时间:2016-04-28 05:23:58.0
有没有可能这样布局:比如TextView的位置距屏幕左边4分之一?
而不是margin-left(屏幕左边) 40dp这样的绝对数值?如果可能,请问分怎么做?
------解决方案--------------------

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
   <View  android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
/>
 <TextView  android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3"
/>
</LinearLayout>

------解决方案--------------------
方法很简单,在空白的地方放个不可见的控件,然后与TextView都设成 0dp 宽,weight 分别设成 1 和 3,当然是要放在 Linearlayout 中了。
------解决方案--------------------
用代码动态处理
------解决方案--------------------
一楼和三楼说的是同一种方法,楼主可以试下,动态写代码 会麻烦点
------解决方案--------------------
动态写代码要对layoutparam做处理,相对麻烦。
  相关解决方案