Add a Textview to a FrameLayout in a determined position

后端 未结 6 1763
旧巷少年郎
旧巷少年郎 2021-01-12 09:18

I\'m trying to add a textView to a frameLayout. The TextView has wrap_content properties, so it grows when the text grows

相关标签:
6条回答
  • 2021-01-12 09:43

    Set FrameLayout properties android:layout_width and android:layout_height to fill_parent and also set TextView property LayoutGravity . such as Center, Right or Top.

    Thanks

    0 讨论(0)
  • 2021-01-12 09:49

    Setting the gravity programatically definitely works Please set the layout_gravity to right in the xml TextView.setGravity(Gravity.RIGHT);

    0 讨论(0)
  • 2021-01-12 09:50

    Try this:

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
    
    ((FrameLayout) findViewById(R.id.mainLayout)).addView(mEditText, params);
    

    Change Gravity to suit your need.

    BTW, the frame layout should use fill_parent for width and height

    0 讨论(0)
  • 2021-01-12 09:51

    Add android:layout_gravity="center" in your frame layout

    <FrameLayout  
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/mainLayout"
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"
        android:layout_gravity="center" > 
    </FrameLayout>
    
    0 讨论(0)
  • 2021-01-12 09:56

    Try to gravity or Layout gravity to your Framelayout or the Textview. It makes your Layout to the center of the screen. Use like this,

    android:layout_gravity="center"
    

    or

    android:gravity="center"
    
    0 讨论(0)
  • 2021-01-12 10:03

    you can try it by set the gravity of text use it like-

    textview.setGravity(Gravity.center);
    

    othervise by xml set gravity to center so it will display you in center and if you'll use centerinparents so it will always apperas at the center of screen.

    0 讨论(0)
提交回复
热议问题