我的布局结构是这样的
LinearLayout
FrameLayout
ImageView
ImageView
FrameLayout
TextView
LinearLayout
我已经为 FrameLayout 内的两个 ImageView 设置了边距。但是 FrameLayout 边距被丢弃,它总是将图像设置为左上角。如果我从 FrameLayout 更改为 LinearLayout,则边距可以正常工作。如何处理?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/inner1"
>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="24px"
android:layout_height="24px"
android:id="@+id/favicon"
android:layout_marginLeft="50px"
android:layout_marginTop="50px"
android:layout_marginBottom="40px"
android:layout_marginRight="70px"
/>
<ImageView
android:layout_width="52px"
android:layout_height="52px"
android:id="@+id/applefavicon"
android:layout_marginLeft="100px"
android:layout_marginTop="100px"
android:layout_marginBottom="100px"
android:layout_marginRight="100px"
/>
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title"
android:layout_marginLeft="10px"
android:layout_marginTop="20px"
android:textColor="#FFFFFF"
android:textSize = "15px"
android:singleLine = "true"
/>
</LinearLayout>
最佳答案
我自己也遇到了同样的问题,并注意到设置 layout_
边距在您同时设置 ImageView 的布局重力即 android:layout_gravity="top"
之前不起作用XML 资源文件,或来自代码:FrameLayout.LayoutParams.gravity = Gravity.TOP;
.
https://stackoverflow.com/questions/5401952/