2015-10-22 1 views
0

У меня есть TextView, высота которого wrap_content. Наверху и внизу находится линия TextView. Мне было интересно, если в любом случае будет изменяться размер линий в зависимости от высоты, определяемой оберткой текста. См. Изображение ниже.Возможно ли, чтобы высота вида реагировала на размер другого вида динамически?

Примечание: фон TextView прозрачный. поэтому я не могу просто провести линию и использовать FrameLayout.

enter image description here

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="@dimen/margin_connection_line" 
    android:layout_marginBottom="@dimen/margin_connection_line" 
     > 

    <View 
     android:id="@+id/top_vertical_line" 
     android:layout_above="@+id/connection_text" 
     android:layout_width="1dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:background="@color/font_white" 
     /> 

    <TextView 
     android:id="@+id/connection_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/margin_larger" 
     android:layout_marginRight="@dimen/margin_larger" 
     android:layout_gravity="center" 
     android:padding="@dimen/margin_larger" 
     android:gravity="center" 
     android:textColor="@color/font_white" 
     android:background="@drawable/connection_white_border" 
     android:text="@string/sample_text" 
     /> 

    <View 
     android:id="@+id/bottom_vertical_line" 
     android:layout_below="@+id/connection_text" 
     android:layout_width="1dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:background="@color/font_white" 
     /> 

</RelativeLayout> 

ответ

2

Я не очень понимаю, если две строки TextViews или просто Views.

В любом случае вы должны использовать простой RelativeLayout. Это должно иметь две линии с шириной 10dp.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" /> 

<View 
    android:layout_width="10dp" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/textView" 
    android:layout_centerHorizontal="true" /> 

<View 
    android:layout_width="10dp" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" /> 

+0

К сожалению, ты прав! Благодаря! –

Смежные вопросы