我有一个包含2个视图的FrameLayout,第二个类似于Close Button (X)
,我想把它放在右边。
我试过layout_gravity =“right ",但没有用。
这是我的布局xml:
<FrameLayout android:layout_width="320dp"
android:layout_height="wrap_content"
android:id="@+id/layoutSmallImg">
<ImageView android:id="@+id/bigImage"
android:layout_width="320dp" android:layout_height="wrap_content"/>
<ImageView android:id="@+id/bigImage"
android:layout_width="320dp" android:layout_height="wrap_content"/>
<ImageButton android:id="@+id/closebutton"
android:background="@android:color/transparent"
android:layout_height="30dp" android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_width="30dp" android:paddingLeft="40dp"
android:visibility="gone"
android:src="@drawable/close" />
</FrameLayout>
发布于 2011-05-19 23:12:04
请改用RelativeLayout。
发布于 2016-02-08 20:20:12
在编程上,您可以使用FrameLayout.LayoutParams设置边距。下面的操作可以将视图放在屏幕底部:
int desired_height_of_content = //whatever your want the height of your view to be
FrameLayout layout = new FrameLayout(this);
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, desired_height_of_content);
int difference = screen_height - desired_height_of_content
flp.setMargins(difference, 0, 0, 0);
layout.addView(your_view, flp);
发布于 2011-05-19 23:17:08
您想使用FrameLayout还是RelativeLayout?
我的理解是,如果您想用另一个视图替换当前视图,则使用FrameLayout。您的需求可以通过RelativeLayout来满足。
https://stackoverflow.com/questions/6060688
复制相似问题