简体   繁体   English

Android中的布局

[英]Layouts in Android

I have two questions. 我有两个问题。

  1. How can I get the spinner in the figure below closer to the text? 如何让下图中的微调器更接近文本?

在此输入图像描述

I use the following xml layout 我使用以下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. How can I change the text of the enter button, as in the below figure, and assign an action to be performed when it is clicked? 如何更改输入按钮的文本,如下图所示,并指定单击时要执行的操作?

在此输入图像描述

1) For the layout design use below code - 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>

Simply remove the weightsum and give the wrap_content as width. 只需删除weightsum并将wrap_content作为宽度。

You can't change the enter button's text. 您无法更改输入按钮的文本。 It's in the default keyboard. 它在默认键盘中。 You have to write yourself one, if you want to have custom button text. 如果你想要自定义按钮文本,你必须自己写一个。

And you can't "assign" an action to the button, but you can implement your type of EditText (assuming that the text fields are of type EditText) which overrides the public boolean onKeyDown (int keyCode, KeyEvent event) and/or public boolean onKeyUp (int keyCode, KeyEvent event) methods (or any other you find suitable for your goal). 并且你不能为按钮“分配”一个动作,但你可以实现你的EditText类型(假设文本字段是EditText类型),它覆盖了public boolean onKeyDown (int keyCode, KeyEvent event)和/或public boolean onKeyUp (int keyCode, KeyEvent event)方法(或任何其他适合您目标的方法)。 Check the EditText's documentation for onKey... methods. 检查EditText文档中的onKey...方法。 In the method you find more suitable you can implement the desired functionality (the action). 在您找到更合适的方法中,您可以实现所需的功能(操作)。

I have found your answer of the 1st Question by using Linear Layout.I suppose it will help you.The Code is as follows:- 我已经通过使用线性布局找到了第一个问题的答案。我想它会对你有帮助。代码如下: -

    <?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>

And for your 2nd Answer this is the link which will lead you to the correct solution.the link is:- Imp Link 对于您的第二个答案,这个链接将引导您找到正确的解决方案。链接是: - Imp Link

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM