说明:通过new ArrayList<T>(List<T> srcList)的方式复制一个集合,是单独开辟了一个内存空间,并且内容跟源集合的内容一样。对新集合的修改并不影响源集合。
布局a再b下,能用代码动态修改为a在b上吗
设置控件布局时:
- LayoutParams leftTxtParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
方法一:addRule(int verb)
- leftTxtParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
方法二:addRule(int verb, int anchor)
- leftTxtParams.addRule(RelativeLayout.END_OF, img_left.getId());
此处第二个参数是控件ID,有关控件ID可以点击查看:
android在代码中为new出的控件设置ID及setId()异常
<RelativeLayout
android
:id=
"@+id/ll_tab_layout_container"
android
:layout_width=
"match_parent"
android
:layout_height=
"match_parent"
android
:fillViewport=
"true"
app
:layout_behavior=
"@string/appbar_scrolling_view_behavior"
>
<android.support.v7.
widget
.CardView
android
:id=
"@+id/card_column"
style=
"@style/home_card_style"
android
:layout_alignParentTop=
"true"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
android
:layout_marginBottom=
"7dp"
android
:layout_marginTop=
"5dp"
>
<RelativeLayout
android
:layout_width=
"match_parent"
android
:layout_height=
"match_parent"
android
:orientation=
"vertical"
>
<com.dx168.efsmobile.me.widget.HomeCardTitleLayout
android
:id=
"@+id/column_more"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
app
:contentIcon=
"@drawable/hundreds_icon"
app
:contentText=
"百家专栏"
app
:rightIcon=
"@drawable/home_right_more_arrow"
app
:rightText=
"查看更多"
/>
<FrameLayout
android
:id=
"@+id/cloumn_fragment"
android
:layout_width=
"match_parent"
android
:layout_height=
"match_parent"
android
:layout_below=
"@+id/column_more"
/>
</RelativeLayout>
</android.support.v7.
widget
.CardView>
<android.support.v7.
widget
.CardView
android
:id=
"@id/card_image"
style=
"@style/home_card_style"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
android
:layout_below=
"@id/card_column"
android
:layout_marginBottom=
"7dp"
android
:layout_marginTop=
"5dp"
>
<ImageView
android
:id=
"@+id/personal"
android
:layout_width=
"match_parent"
android
:layout_height=
"72dp"
android
:scaleType=
"fitXY"
/>
</android.support.v7.
widget
.CardView>
<FrameLayout
android
:id=
"@+id/fl_live_container_bottom"
android
:layout_below=
"@id/card_image"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
/>
</RelativeLayout>
if
(isActiveUser){
RelativeLayout.LayoutParams imgParams = (RelativeLayout.LayoutParams)
mImgCardView
.getLayoutParams()
;
imgParams.addRule(RelativeLayout.
BELOW
,
0
)
;
imgParams.addRule(RelativeLayout.
ALIGN_PARENT_TOP
)
;
mImgCardView
.setLayoutParams(imgParams)
;
RelativeLayout.LayoutParams columnParams = (RelativeLayout.LayoutParams)
mlColumnCardView
.getLayoutParams()
;
columnParams.addRule(RelativeLayout.
ALIGN_PARENT_TOP
,
0
)
;
columnParams.addRule(RelativeLayout.
BELOW
,
mImgCardView
.getId())
;
//or params
mlColumnCardView
.setLayoutParams(columnParams)
;
}
else
{
RelativeLayout.LayoutParams
columnParams
= (RelativeLayout.LayoutParams)
mlColumnCardView
.getLayoutParams()
;
columnParams
.addRule(RelativeLayout.
BELOW
,
0
)
;
columnParams
.addRule(RelativeLayout.
ALIGN_PARENT_TOP
)
;
mlColumnCardView
.setLayoutParams(
columnParams
)
;
RelativeLayout.LayoutParams imgParams = (RelativeLayout.LayoutParams)
mImgCardView
.getLayoutParams()
;
imgParams.addRule(RelativeLayout.
ALIGN_PARENT_TOP
,
0
)
;
imgParams.addRule(RelativeLayout.
BELOW
,
mlColumnCardView
.getId())
;
mImgCardView
.setLayoutParams(imgParams)
;
}