Search code examples
androidlayouttextviewimageviewdivider

How to surrounded TextView with 2 divider


My question is how to surround a TextView with 2 dividers in Android like this:

-------- TEXTVIEW ------

where "--------" is a horizontal divider in an ImageView.

I tried with a LinearLayout horizontal but I had some space and my divider was too small.


Solution

  • Try this:

    replace drawable with your image

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="3" >
    
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher" />
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView"
                android:layout_gravity="center" 
                android:gravity="center"/>
    
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content" 
                android:layout_weight="1"
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"/>
        </LinearLayout>