【问题标题】:android:layout_alignParentRight="true"doesn't workandroid:layout_alignParentRight="true"不起作用
【发布时间】:2014-06-18 16:09:57
【问题描述】:

我在LinearLayout中有一个FrameLayout,我想把它放在右边。试过android:layout_alignParentRight="true",但似乎没有用。任何想法为什么?请参阅下面的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/gap_normal"
    android:orientation="horizontal"
    android:background="@color/grey"
    android:layout_alignParentRight="true">


    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="right"
        android:layout_alignParentRight="true">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/pb"
            android:visibility="invisible"/>

        <CheckableImageButton
            android:id="@+id/conference_checkableimagebutton_lockstate"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"
            android:background="@android:color/white"
            android:src="@drawable/conference_checkableimagebutton_lockstate_src"
            android:cropToPadding="false"/>

    </FrameLayout>

    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/conference_text_lockstate"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/gap_normal"
        android:layout_marginBottom="@dimen/gap_normal"
        android:gravity="left"
        android:textSize="@dimen/textsize_normal"
        android:paddingRight="@dimen/gap_large"
        android:text="Unlocked. When all participants have joined, lock the conference by tapping the padlock."
        app:typeface="roboto_condensed_regular" />

</LinearLayout>    

【问题讨论】:

    标签: android xml mobile android-framelayout


    【解决方案1】:

    试试这个代码:

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" > 
    
    
    <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="right"
            android:layout_alignParentRight="true">
    
            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/pb"
                android:visibility="invisible"/>
    
            <CheckableImageButton
                android:id="@+id/conference_checkableimagebutton_lockstate"
                android:layout_width="60dp"
                android:layout_height="match_parent"
                android:scaleType="fitCenter"
                android:adjustViewBounds="true"
                android:background="@android:color/white"
                android:src="@drawable/conference_checkableimagebutton_lockstate_src"
                android:cropToPadding="false"/>
    
            </FrameLayout>
    
        <com.devspark.robototextview.widget.RobotoTextView
            android:id="@+id/conference_text_lockstate"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/gap_normal"
            android:layout_marginBottom="@dimen/gap_normal"
            android:gravity="left"
            android:textSize="@dimen/textsize_normal"
            android:paddingRight="@dimen/gap_large"
            android:text="Unlocked. When all participants have joined, lock the conference by tapping the padlock."
            app:typeface="roboto_condensed_regular" />
    
    
    
    
    
    </RelativeLayout>   
    

    【讨论】:

      【解决方案2】:

      android:layout_alignParentRight=“true”doesn't work,因为您的父级是 LinearLayoutalignParentRight(以及所有其他 relative 属性)仅适用于 RelativeLayouts

      【讨论】:

      • 问题是,我需要第一个线性布局,那么在这种情况下我可以做些什么吗?
      • 我的回答是正确的。如果你想要(你必须向我解释为什么你说你“需要”)一个 LinearLayout,那么你就不能使用相对属性。很简单。
      • Any ideas why? 是的。已回答。
      猜你喜欢
      • 2014-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多