的FrameLayout保证金不工作 [英] FrameLayout margin not working

查看:131
本文介绍了的FrameLayout保证金不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局结构是这样的

 的LinearLayout
    的FrameLayout
       ImageView的
       ImageView的
    的FrameLayout
    的TextView
的LinearLayout
 

我已经设置保证金的两个ImageView的这是里面的FrameLayout。但是的FrameLayout利润都将被丢弃,它始终设置的图像到左上角。如果我从的FrameLayout更改为正确的LinearLayout边缘的工作。如何处理呢?

 < XML版本=1.0编码=UTF-8&GT?;
    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=横向
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / inner1
    >
        <的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
           机器人:layout_width =WRAP_CONTENT
           机器人:layout_height =WRAP_CONTENT
        >

            < ImageView的
             机器人:layout_width =24PX
             机器人:layout_height =24PX
             机器人:ID =@ + ID /图标
             机器人:layout_marginLeft =50像素
             机器人:layout_marginTop =50像素
             机器人:layout_marginBottom =40PX
             机器人:layout_marginRight =70px

            />
            < ImageView的
             机器人:layout_width =52px
             机器人:layout_height =52px
             机器人:ID =@ + ID / applefavicon
             机器人:layout_marginLeft =100像素
             机器人:layout_marginTop =100像素
             机器人:layout_marginBottom =100像素
             机器人:layout_marginRight =100像素
            />

        < /的FrameLayout>
            <的TextView
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:ID =@ + ID /标题
            机器人:layout_marginLeft =10px的
            机器人:layout_marginTop =20像素
            机器人:文字颜色=#FFFFFF
            机器人:TEXTSIZE =15px的
            机器人:单线=真
            />

    < / LinearLayout中>
 

解决方案

我有同样的问题我自己,发现设置布局_ 利润率不工作,直到你还设置您的ImageView的布局重心即安卓layout_gravity =顶在XML资源文件,或code: FrameLayout.LayoutParams.gravity = Gravity.TOP;

My layout structure is like this

LinearLayout
    FrameLayout
       ImageView
       ImageView
    FrameLayout
    TextView
LinearLayout

I have set margin's for the two ImageView which are inside FrameLayout. But FrameLayout margins are discarded and it always set's the Image to top left corner. If i change from FrameLayout to LinearLayout the margin's work properly. How to handle this ?

<?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>

解决方案

I had the same issue myself and noticed that setting the layout_ margins does not work until you also set your ImageView's layout gravity i.e. android:layout_gravity="top" in the XML resource file, or from code: FrameLayout.LayoutParams.gravity = Gravity.TOP;.

这篇关于的FrameLayout保证金不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆