2016-07-14 60 views
0

我想在TextView中的每個字符之間有一條線。我怎麼能在TextView中有一個字符分隔線

原來的TextView能做到這一點嗎?如果不是,我該怎麼做?

+0

你可以用|符號另外需要添加查看在TextView –

+0

之間如何使查看 – Sumit

+0

您需要使用單獨的TextView查看全部0的答案 –

回答

0

你可以使用這個庫

https://github.com/pinball83/Masked-Edittext

 [![enter image description here][1]][1] 
    <com.github.pinball83.maskededittext.MaskedEditText 
      android:id="@+id/masked_edit_text" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      app:mask="*|*|*|*|*" 
      app:notMaskedSymbol="*" 
      app:maskIcon="@drawable/abc_ic_clear_mtrl_alpha" 
      app:maskIconColor="@color/colorPrimary" 
      /> 

enter image description here

enter image description here

+0

抱歉,但此代碼不起作用 – Sumit

+0

再次檢查答案。 –

0

如果你從XML填充你的TextView,你可以做以下

android:text="Line1: \n Line2 \n Line3" 

您還可以指定的行數與android:lines="2"

然後你就可以用\ n

它們分開

此外,您可以執行以下操作(嘗試從代碼更新文本時):

String newText = "Line 1" 
      + System.getProperty ("line.separator") 
      + "Line 2" 
      + System.getProperty ("line.separator"); 
1

單個textview將無法做到這一點。所以

嘗試

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/item1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:gravity="center" 
     android:text="0" 
     android:textSize="24sp" /> 

    <View 
     android:layout_width="1dip" 
     android:layout_height="40dip" 
     android:background="#000000" /> 

    <TextView 
     android:id="@+id/item2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:gravity="center" 
     android:text="0" 
     android:textSize="24sp" /> 

    <View 
     android:layout_width="1dip" 
     android:layout_height="40dip" 
     android:background="#000000" /> 

    <TextView 
     android:id="@+id/item3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:gravity="center" 
     android:text="0" 
     android:textSize="24sp" /> 

    <View 
     android:layout_width="1dip" 
     android:layout_height="40dip" 
     android:background="#000000" /> 

    <TextView 
     android:id="@+id/item4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="2dp" 
     android:gravity="center" 
     android:text="0" 
     android:textSize="24sp" /> 

    <View 
     android:layout_width="1dip" 
     android:layout_height="40dip" 
     android:background="#000000" /> 
</LinearLayout > 
+0

是不是這個有用的?@Sumit –

+0

如果我的回答幫助你比接受作爲回答,所以其他用戶將被引導。@ Sumit –

0

試試這個,

main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:padding="3dp" 
      android:orientation="horizontal" 
      android:background="@drawable/outline" 
      android:layout_height="wrap_content"> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textColor="#000000" 
    android:gravity="center" 
    android:text="0" 
    android:textSize="20dp"/> 

<View android:layout_width="2dp" 
    android:layout_height="match_parent" 
    android:background="#353535"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textColor="#000000" 
    android:text="0" 
    android:gravity="center" 
    android:textSize="20dp"/> 

<View android:layout_width="2dp" 
    android:layout_height="match_parent" 
    android:background="#353535"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textColor="#000000" 
    android:gravity="center" 
    android:text="0" 
    android:textSize="20dp"/> 

<View android:layout_width="2dp" 
    android:layout_height="match_parent" 
    android:background="#353535"/> 


<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:textColor="#000000" 
    android:gravity="center" 
    android:text="0" 
    android:textSize="20dp"/> 

<View android:layout_width="2dp" 
    android:layout_height="match_parent" 
    android:background="#353535"/> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:textColor="#000000" 
    android:text="0" 
    android:textSize="20dp"/> 

    </LinearLayout> 

outline.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape"> 
<stroke android:width="2dp" android:color="#353535" /> 
<padding android:left="2dp" 
    android:top="2dp" 
    android:right="2dp" 
    android:bottom="2dp" /> 
<corners android:radius="0dp" /> 
<solid android:color="#ffffffff" /> 
</shape> 

截圖

screenshot

這種力量可以幫助你

+0

謝謝你UI正在工作 – Sumit

+0

請接受我的回答。那麼只有其他人可以輕鬆找到正確答案 –

相關問題