[英]Programatically change relative layout postion with its child views
How can I change the position of layout id: rl_generic relative layout programatically? 如何以编程方式更改布局ID:rl_generic相对布局的位置? Currently it is centered.
当前它居中。 I want its position to change to top left corner for 10 seconds & then top right corner for next 10 seconds with its child views.
我希望其位置更改为左上角10秒钟,然后在接下来的10秒钟内更改其子视图的右上角。
<RelativeLayout
android:id="@+id/ClockScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/rl_generic"
android:visibility="visible" >
<TextView
android:id="@+id/TimeDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="12:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="100sp" />
<TextView
android:id="@+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/TimeDisplay"
android:layout_centerHorizontal="true"
android:paddingTop="1dp"
android:text="" />
</RelativeLayout>
</RelativeLayout>
Use the Following code to change the position of your layout. 使用以下代码更改布局的位置。
public class SampleActivity extends Activity {
private RelativeLayout miView;
private RelativeLayout.LayoutParams params;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
miView = (RelativeLayout) findViewById(R.id.rl_generic);
params=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.d("Sample Acitivity::", "Inside Run MTHD:::");
miView.setLayoutParams(params);
}
}, 5000);
}
}
Let me know your feedbacks.. 让我知道您的反馈。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.