2012-06-13 61 views
0

我有兩個問題。Android中的佈局

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

enter image description here

我使用下面的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> 
  • 我怎樣才能改變輸入按鈕的文本,如在下面圖中,並在點擊時指定要執行的操作?
  • enter image description here

    +0

    你可以試試這個使用'RelativeLayout' – Praveenkumar

    +0

    我不知道我理解你的問題,但是你想要在按鈕上有輸入圖標嗎?如果是這種情況,可以使用ImageButton並將背景設置爲@null,將src設置爲輸入按鈕的可繪製對象。 –

    回答

    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作爲寬度。

    +0

    第2部分 – AMH

    +0

    我從來沒有嘗試過這一個伴侶。而且,我也不知道那個。但是,我會盡力在這裏更新 – Praveenkumar

    +0

    ,感謝很多@Spk – AMH

    1

    您無法更改輸入按鈕的文本。它在默認鍵盤中。如果你想要自定義按鈕文字,你必須自己寫一個。

    您不能將操作「分配」給按鈕,但是您可以實現您的EditText類型(假設文本字段類型爲EditText),該類型覆蓋了方法(或其他任何其他方法你覺得適合你的目標)。檢查EditText文檔的onKey...方法。在該方法中,您發現更適合您可以實現所需的功能(操作)。

    0

    我以線性Layout.I想這將有助於you.The代碼如下發現你的第一問題的答案: -

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