问题
I have a xml that the basic "skeleton" is
<RelativeLayout>
<FrameLayout>
<RelativeLayout>
<TextView>
</TextView>
<TextView>
</TextView>
</RelativeLayout>
<DrawView>
//The view that changes 1
</DrawVIew>
<EditText>
//The view that changes 2
</EditText>
</FrameLayout>
<RelativeLayout>
</RelativeLayout>
</RelativeLayout>
What I want is that using code the DrawView goes up or down, so sometimes you can use the DrawView and in other moments you can use the EditText, but ever the two views are showed.
How can I do that?
回答1:
Since you are placing both widgets inside a FrameLayout you can change its gravity like below:
FrameLayout.LayoutParams drawViewLayoutParams = drawView.getLayoutParams();
drawViewLayoutParams.gravity = Gravity.BOTTOM;
FrameLayout.LayoutParams editTextLayoutParams = editText.getLayoutParams();
editTextLayoutParams.gravity = Gravity.TOP;
回答2:
The only way to do this is to remove all of the FrameLayout
's children and put them back in the order you need.
Or you can use another RelativeLayout and change the LayoutParams for the two Views
来源:https://stackoverflow.com/questions/15997992/how-to-put-up-or-down-a-view-programatically