2017-11-17 2 views
0

Ich mag würde eine Linie in der Nähe eines Textview wie das img unten in Android hinzuzufügen:Add Linie in der Nähe von Textview

line near text view

hier ist mein xml-Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/grey"> 
    <Switch 
     android:id="@+id/bluetoothSwitch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true" 
     android:paddingBottom="8dp" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     android:paddingTop="8dp" 
     android:text="Bluetooth" 
     android:textSize="30sp" 
     android:background="@android:color/white"/> 
    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/bluetoothSwitch" 
     android:layout_marginTop="20dp" 
     android:background="@android:color/white" 
     android:divider="?android:dividerVertical" 
     android:dividerPadding="8dp" 
     android:orientation="vertical" 
     android:showDividers="middle"> 
     <Button 
      android:id="@+id/btn1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/bluetoothSwitch" 
      android:layout_gravity="start" 
      android:background="?android:attr/selectableItemBackground" 
      android:paddingBottom="8dp" 
      android:paddingLeft="18dp" 
      android:paddingTop="8dp" 
      android:text="Scan" 
      android:textAlignment="viewStart" 
      android:textAllCaps="false" 
      android:textSize="20sp" /> 

     <Button 
      android:id="@+id/btn2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/btn1" 
      android:layout_gravity="start" 
      android:background="?android:attr/selectableItemBackground" 
      android:paddingBottom="8dp" 
      android:paddingLeft="18dp" 
      android:paddingTop="8dp" 
      android:text="Show Paired Device" 
      android:textAlignment="viewStart" 
      android:textAllCaps="false" 
      android:textSize="20sp" /> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/linearLayout1" 
     android:layout_marginTop="20dp" 
     android:paddingLeft="16dp" 
     android:text="PAIRED DEVICE: " 
     android:background="@android:color/white" 
     android:paddingBottom="8dp" 
     android:paddingTop="8dp"/> 
</RelativeLayout> 

und mein app Bildschirm :

where a would like to add line

ich nahm diesen Screenshot fr om meine Samsung Einstellungen. Ich würde die Zeile in der Nähe der Textansicht "gepaartes Gerät" hinzufügen. Ich lese, um Ansicht zu verwenden, aber ich kann es nicht tun. Kann mir jemand helfen? danke allen

+0

verwenden, um Textview ein '' mit einer Höhe von ' 1dp' und alle anderen Attribute wie Farbe etc .. Umschließen Sie 'Textview' und' View' in einem 'LinearLayout' mit horizontaler Ausrichtung. –

Antwort

0

Diese Arbeit wird und ausgerichtet werden immer

<RelativeLayout 
     android:padding="8dp" 
     android:layout_gravity="center" 
     android:gravity="center_vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/tvTitle" 
      android:layout_weight="1" 
      android:layout_marginRight="8dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="Wifi Cellular" 
      android:textSize="20sp"/> 

     <View 
      android:layout_toRightOf="@+id/tvTitle" 
      android:layout_centerVertical="true" 
      android:layout_weight="1" 
      android:background="#636363" 
      android:layout_width="match_parent" 
      android:layout_height="2dp"/> 

    </RelativeLayout> 

Probenarbeit enter image description here

+0

sehr gute Antwort, danke !! – Tenrampi

0

Try this:

 <LinearLayout 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Your Text" 
      /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="0.7dp" 
      android:background="#dddddd" 
      android:layout_gravity="center_vertical" 
      /> 

    </LinearLayout> 

Ändern Sie die Hintergrundfarbe der Ansicht zu jeder Farbe und ändern Sie die Höhe entsprechend und legen margin auch, wenn nötig. Hoffe, das hilft.

0

so etwas wie dieses Try -

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center_vertical"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TEXT"/> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black" /> 

    </LinearLayout> 
Verwandte Themen