2013-05-09 114 views
2

我有3個元素在LinearLayout需要適合在屏幕上,目前他們沒有。內容在Android屏幕外

這裏是我希望它看起來

TextView - TextView - EditText

但是第二TextView是相當長的,它推動EditText關閉屏幕

所以它結束看起來像這樣

TextView ---(屏幕結束)| TextView -------- |(屏幕結束)EditText

我環顧了一下,我似乎無法找到解決方案,應該是一個簡單的解決方案。如果這是重複的,請隨時將我與適當的答案聯繫起來,因爲我無法自己找到答案。

下面是代碼,感謝您的幫助

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/iline_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:background="@color/white" 
    android:gravity="center" 
    android:orientation="vertical" > 

<LinearLayout 
     android:id="@+id/ll3" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/b" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/distance_edge" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ems="4" /> 
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

最後,我想第二個TextView佔用同一空間33%,寬度爲別人的,只是換行文本多必要時要做到這一點

編輯

第一個文本視圖僅僅是一個字母B),所以我不得不設置該包的內容,那麼其他人工作得很好

下面是代碼

<LinearLayout 
     android:id="@+id/ll3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"     
      android:text="@string/b" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/distance_edge" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:ems="4" /> 
    </LinearLayout> 
+0

嘿最後一個問題,所以我沒有啓動另一個線程。你看到@mmBs字符串的底部是如何被截斷的?這個詞的文字是那裏的一半。我如何解決這個問題? – IrishWhiskey 2013-05-09 01:53:54

回答

2

現在是正確的肯定 - 我在IDE檢查它。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/iline_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@color/white" 
     android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/ll3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:layout_gravity="center" > 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="some long, long, long text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="some long, long, long, long, long, long, long, long, long text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:ems="4" /> 
    </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

Screen

+0

nope,但我編輯我的文章因爲我認爲這個版面之外的版面會有一些變化。 – IrishWhiskey 2013-05-09 00:57:58

+0

複製並粘貼我的代碼。在我的IDE中,一切正常,只要你需要。 – mmBs 2013-05-09 01:15:36

+0

是的,它會的。除非你錯過了一個非常關鍵的點。第二個字符串就像我第二個字符串的長度的五分之一。嘗試將東西放入5倍的時間 – IrishWhiskey 2013-05-09 01:17:06

1

嘗試設置爲您的文本的意見和編輯文本權重屬性。輸出可能看起來有點尷尬,這取決於你的字符串是什麼以及它們如何包裝。

<LinearLayout 
     android:id="@+id/ll3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.33" 
      android:text="Some string" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.33" 
      android:text="some really, really, really, long string" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="0.33" 
      android:ems="4" /> 
    </LinearLayout> 
+0

對不起,它沒有工作。完全相同的問題,中間的一個擴大並將其他兩個從屏幕上推開,但它確實是新線。另外它咆哮着使用嵌套權重說「對性能不好」。 – IrishWhiskey 2013-05-09 00:30:33

+0

您是否看到我的示例在封裝LinearLayout中沒有重量屬性?如果有任何方法可以使用封閉線性佈局上方的另一個線性佈局以外的某種佈局,則只要警告發生,就會處於良好狀態。完美地工作在我的最後。 – MarsAtomic 2013-05-09 01:07:04

2
<LinearLayout 
    android:id="@+id/ll3" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:weightSum="3" 
    android:gravity="center" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/b" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/textView6" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/distance_edge" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:ems="4" /> 
</LinearLayout> 
+0

Hey Hoan!很高興再次見到你,不幸的是你的解決方案也無法工作。它實際上使整個佈局消失在我的屏幕上。 – IrishWhiskey 2013-05-09 00:44:54

+0

這個佈局是更大布局的一部分嗎? – 2013-05-09 00:45:46

+0

我編輯了答案,我剪下並粘貼,忘記了layout_witdth =「0dp」 – 2013-05-09 00:49:06