簡體   English   中英

Android中的布局

[英]Layouts in Android

我有兩個問題。

  1. 如何讓下圖中的微調器更接近文本?

在此輸入圖像描述

我使用以下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. 如何更改輸入按鈕的文本,如下圖所示,並指定單擊時要執行的操作?

在此輸入圖像描述

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM