【问题标题】:layout_marginLeft works as right on Android API < 11 when View in FrameLayout当在 FrameLayout 中查看时,layout_marginLeft 在 Android API < 11 上正常工作
【发布时间】:2013-02-21 10:44:12
【问题描述】:

当我使用layout_marginLeft 或从代码设置左边距时,它的工作方式为layout_marginRight。当我将Viewlayout_marginLeft 放在FrameLayout 或Android API

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:background="#77cc99"
        >
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dp"
        android:background="#eebbaa">
        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Hello World, MyActivity"
                />
        </FrameLayout>

</FrameLayout>

【问题讨论】:

    标签: android android-framelayout


    【解决方案1】:

    默认情况下,android:layout_gravity 属性设置为 FrameLayout 的“左”。如果你想使用android:layout_marginLeft,你应该改变它:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_marginLeft="50dp"
        android:background="#77cc99"
        android:orientation="vertical" >
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:layout_marginLeft="50dp"
            android:background="#eebbaa" >
    
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Hello World, MyActivity" />    
        </FrameLayout>
    </FrameLayout>
    

    【讨论】:

    • 我喜欢这个答案:D,谢谢你救了我(我已经浪费了 1 天)
    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 2022-12-18
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多