5

I have tried to move the button using graphical interface and android:layout_alignParentLeft in XML file, anyway it does not work. My Android Studio version is 2.2.3. Have you ever had this problem?

enter image description here

1
  • please show your xml code.. Commented Dec 30, 2016 at 11:49

2 Answers 2

9

You need RelativeLayout or other simlilar layout as parent container because FrameLayout just draw the views one over another plus you should check the properties section to see the attibute properties that you can apply on your layout.

To read further about ViewGroups and it's sub-types with their behaviours

3
  • 1
    @MMManuel i am glad that i could help , happy coding :) Commented Dec 30, 2016 at 11:52
  • Then why should we even use FrameLayout and not just always RelativeLayout? FrameLayout seems to be useless in most cases. Only usefull for webView which needs the whole area.
    – Black
    Commented Jan 22, 2019 at 15:20
  • @Black it's useful for fragment transition at run time and when you have multiple view one over another and only wants to show the one at top, or like you want to display a description view on the top of a image etc.. Commented Feb 7, 2019 at 0:59
4

If you forced to use FrameLayout(e.g in Toolbar or so) and you have only one element(or small amount) to operate with(button) you can use android:layout_gravity="" attribute to align element in the FrameLayout.

   <FrameLayout
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:text="@string/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
    </FrameLayout>

If you have have few elements in your layout, you can: 1) Change FrameLayout to RelativeLayout or 2)Wrap all items into Relative layout and set parameters to match_parent

    <FrameLayout
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:text="@string/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"/>
    </RelativeLayout>
    </FrameLayout>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.