0 votes
1 view
in Java by (10.2k points)

I know it sounds easy. I need to put a text in center, but when the text is too long it needs to go below, but still align in the center of my xml.

Here's my code :

 <LinearLayout

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:id="@+id/showdescriptioncontenttitle"

    android:paddingTop="10dp"

    android:paddingBottom="10dp"

    android:layout_centerHorizontal="true"

>

    <TextView 

        android:id="@+id/showdescriptiontitle"

        android:text="Title"

        android:textSize="35dp"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

    />

</LinearLayout>

I put paddingTop and Bottom because I need some space. PS: My code is bigger; it's in a RelativeLayout.

1 Answer

0 votes
by (46.1k points)
Set also android:gravity parameter in TextView to center.

For testing the effects of different layout parameters I recommend to use different background color for every element, so you can see how your layout changes with parameters like gravity, layout_gravity or others.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Oct 15, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Sep 9, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Nov 20, 2019 in Java by Anvi (10.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...