在Android中,FrameLayout是一个容器ViewGroup,用于放置和管理子View的位置。可以通过以下方法设置FrameLayout中子View的位置:
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:layout_gravity="center"/> </FrameLayout>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:layout_marginLeft="20dp" android:layout_marginTop="20dp"/> </FrameLayout>
FrameLayout frameLayout = findViewById(R.id.frameLayout); frameLayout.setPadding(20, 20, 20, 20);
通过以上方法可以灵活地设置FrameLayout中子View的位置,实现不同的布局效果。