【发布时间】:2016-04-14 15:41:29
【问题描述】:
我在我的应用程序中的某个地方感到震惊。我的应用程序上有 50 个按钮。只要按下按钮,我想显示文本并在释放时隐藏它。此外,在按下另一个按钮时,文本应在释放时更改并隐藏,依此类推。文本的位置保持不变。 (另外,我们可以使用 X 和 Y 坐标来设置文本的位置吗?)
下面是我的 XML
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/NUMBERS"
android:textColor="#ecaa00"
android:textSize="28sp"
android:padding="10dip"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="3dip">
<Button
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/ONE" />
<Button
android:id="@+id/two"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/TWO" />
<Button
android:id="@+id/three"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/THREE" />
<Button
android:id="@+id/four"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/FOUR" />
<Button
android:id="@+id/five"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/FIVE" />
</LinearLayout>
</LinearLayout>
PS:有很多按钮,为每个按钮设置可见属性并在释放时隐藏它们需要大量代码行。有没有更好的方法来实现同样的目标?例如引用按钮,按下时显示文本并在释放时隐藏。
【问题讨论】:
标签: android button text show-hide