2013-04-05 4 views
2

나는 ... 그것은 위의 같은 UI를 제공선형 레이아웃 포장 텍스트 뷰

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/messageText" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="12:45 PM" /> 

</LinearLayout> 

을 다음과 같이 내가 필요한 완벽한 Long Text Image

를 레이아웃을 설계하고있다. 긴 텍스트는 방향이 수평이므로 버튼을 화면에서 누르지 않아도 제대로 포장됩니다. 버튼도 늘어지지 않습니다.

하지만 텍스트가 작 으면 이 버튼은 내가 1 레이아웃 체중을 넣어 내가 아는이

short correct text

같은 텍스트의 왼쪽 끝으로 정렬되어야합니다 내가 원하는입니다이

Short text image

것 같습니다.

버튼에 필요한 공간을 제공 한 후 남은 전체 영역을 소모합니다.

나는 그것을 넣지 않습니다. 너비를 감싸는 내용으로 만드십시오. 짧은 텍스트에 효과적입니다. 하지만 텍스트가 커짐에 따라

버튼을 누르면 화면에서 버튼이 밀려납니다.

문제가 있습니다. 희망을 충분히 설명해 주길 바래요. 그러나 물론 오랫동안 읽어야합니다. 물론 고통 스럽다. 그러나 포인터를 아는 것이 정말 기쁠 것입니다.

상대 레이아웃을 사용하는 것을 꺼려하지 않습니다.

도움이 될 것입니다.

감사합니다.

답변

5

희망이 있습니다. 이것을 시도하십시오 :

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

<TextView 
    android:id="@+id/messageText" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="12:45 PM" /> 

을 당신이 안드로이드 변경할 필요가 있다고 생각이 시도 layout_width = "wrap_content"

+0

고마워요. 내 밤을 구했다 :) – Javanator

1

을 : 안드로이드에있는 LinearLayout의을 layout_width = "fill_parent"를

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

<TextView 
    android:id="@+id/messageText" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="1.0" 
    android:text="Some really long text asd asd asd asd asd asd asd asd asd asd asd![enter image description here][1]" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:text="12:45 PM" /> 

0

나는 그것을 내 장치에서 테스트하여 정상적으로 작동합니다. 그것을 시도하십시오

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:weightSum="1" > 

<TextView 
    android:id="@+id/messageText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="sdgdsgdhdhdfhdhgfffffffffffffffffffffffffffffffffffffffff" /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="12:45 PM" /> 

</LinearLayout>