2014-02-14 4 views
1
다음

에서 화면을 이동 텍스트 뷰하는 레이아웃입니다 :이 RelativeLayout의

<?xml version="1.0" encoding="utf-8"?> 

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:columnCount="2" 
    android:rowCount="2" 
    android:rowOrderPreserved="true" 
    android:alignmentMode="alignMargins"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="0" 
     android:layout_column="0" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Test:" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="0" 
     android:layout_column="1" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="too long line too long line too long line too long line" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Test2:" 
     android:paddingRight="10dp" 
     android:layout_row="1" 
     android:layout_column="0" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_row="1" 
     android:layout_column="1" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Test line" /> 
</GridLayout> 

여기 무슨 일의 스크린 샷입니다 : 내가 두 번째 텍스트 뷰를 방지 할 수있는 방법

TextView

합니다 (하나의 선택 스크린 샷)이 화면 경계를 넘어 가지 않습니까?

답변

6

각 textview에 match_parent 너비와 적절한 layout_weight를 지정하면이 문제를 피할 수 있습니다. 아래 코드는 필요한 것을 정확하게 제공합니다. 즐겨!

<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:text="Test 1"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="line too long line too long line too long line too long line too long "/> 
     </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:text="Test 2"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="line too long line too long line too long line too long line too long "/> 
    </LinearLayout> 

</LinearLayout> 
+1

하지만 대답은 그것을 할 수있는 올바른 방법을 보여주는 코드를 추가하는 예를 들어, 좀 더 정교한 수 : 은 텍스트 뷰에서 다음 줄을 놓습니다. 그래도 좋은 해결책;) – 2Dee

+0

나는 그것을 사과한다. 약간의 서두를했지만 도움을 원했습니다 :) –

+0

@TheHungryAndroider : 감사합니다. layout_weight를 사용하여 예제를 게시 할 수 있습니까? – xx77aBs

1

이것은 textView 너비가 wrap_content이기 때문입니다. 그래서 텍스트가 너무 길면 스크린 밖에있을 것입니다. 그래서 더 좋은 방법은 match_parent으로 설정하는 것입니다.

예, 너무 길면 MaxLines을 설정할 수 있습니다.

3

대답은 쉽습니다. 단 3 줄의 XML 코드. 이 갈 올바른 방법입니다

<TextView 
    android:layout_width = "match_parent" 
    android:layout_height = "wrap_content" 
    android:width = "0dp"/>