[英]Layouts in Android
我有两个问题。
我使用以下xml布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Check by"
android:layout_weight="1"
android:textSize="20dp"/>
<Spinner
android:id="@+id/CheckBy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:enabled="false"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Outcome"
android:layout_weight="1"
android:textSize="20dp"/>
<Spinner
android:id="@+id/Outcome"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20dp"
android:enabled="false"/>
</LinearLayout>
1)对于布局设计使用下面的代码 -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check by"
android:textSize="20dp"
/>
<Spinner
android:id="@+id/CheckBy"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:enabled="false"
/>
<TextView
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:text="Outcome"
android:textSize="20dp"
/>
<Spinner
android:id="@+id/Outcome"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:enabled="false"
/>
</LinearLayout>
只需删除weightsum
并将wrap_content
作为宽度。
您无法更改输入按钮的文本。 它在默认键盘中。 如果你想要自定义按钮文本,你必须自己写一个。
并且你不能为按钮“分配”一个动作,但你可以实现你的EditText类型(假设文本字段是EditText类型),它覆盖了public boolean onKeyDown (int keyCode, KeyEvent event)
和/或public boolean onKeyUp (int keyCode, KeyEvent event)
方法(或任何其他适合您目标的方法)。 检查EditText文档中的onKey...
方法。 在您找到更合适的方法中,您可以实现所需的功能(操作)。
我已经通过使用线性布局找到了第一个问题的答案。我想它会对你有帮助。代码如下: -
<?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/lblCheckBy"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:gravity="right"
android:text="Check by" />
<Spinner
android:id="@+id/spnCheckBy"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<TextView
android:id="@+id/lblOutcome"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:gravity="right"
android:text="Outcome" />
<Spinner
android:id="@+id/Outcome"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
</LinearLayout>
对于您的第二个答案,这个链接将引导您找到正确的解决方案。链接是: - Imp Link
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.