当前位置: 代码迷 >> Android >> 怎么设置RelativeLayout布局中多个ImageView的前后关系
  详细解决方案

怎么设置RelativeLayout布局中多个ImageView的前后关系

热度:36   发布时间:2016-04-28 04:30:38.0
如何设置RelativeLayout布局中多个ImageView的前后关系?
<RelativeLayout android:id="@+id/layout_middle"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/dp_05"
        android:scaleType="center"
        android:background="@color/cl_black" >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitCenter"
            android:id="@+id/imageview_1" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_2"
            android:scaleType="fitCenter"
            android:id="@+id/imageview_2" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_3"
            android:scaleType="fitCenter"
            android:id="@+id/imageview_3" />
</RelativeLayout>

问上面RelativeLayout布局中有三个ImageView,如何在程序中动态设置其前面关系?
------解决方案--------------------
相对布局有个below,above, rightOf ,leftOf 等属性,你查一下文档。
------解决方案--------------------
RelativeLayout 类有一个 LayoutParams 内部类 , 可以设置各种 xml 属性给这个内部类, 然后设置给对应的组件;


RelativeLayout.LayoutParams(Context c, AttributeSet attrs)
RelativeLayout.LayoutParams(int w, int h)
RelativeLayout.LayoutParams(ViewGroup.LayoutParams source)
RelativeLayout.LayoutParams(ViewGroup.MarginLayoutParams source)
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams source)
Copy constructor.
  相关解决方案