【发布时间】:2016-11-17 03:48:39
【问题描述】:
【问题讨论】:
-
你可以用 |否则需要在TextView之间添加View
-
你需要为所有 0 使用单独的 TextView 看我的回答
-
请接受我的回答。那么只有其他人才能轻松找到正确答案
标签: android xml android-layout android-studio textview
【问题讨论】:
标签: android xml android-layout android-studio textview
你可以使用这个库
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"
/>
【讨论】:
如果您从 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");
【讨论】:
单个 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 >
【讨论】:
试试这个,
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>
截图
这可能对你有帮助
【讨论】: