2014-10-01 2 views
0

확장 가능한 목록의 각 행에 버튼이 있고, 아래는 같은 줄에 있어야하는 텍스트보기와 버튼을위한 XML 레이아웃 파일이지만 텍스트는 "Assign Badge"는 너무 길어서 텍스트 크기를 작게 만들지 않으면 한 줄 = true로 맞지 않습니다. 텍스트가 절반 밖에 표시되지 않기 때문에 도움이되지 않습니다. 버튼이 두 줄에 나타납니다 ... 버튼을 넓힐 수있는 방법이 있습니까? 감사.안드로이드 단추 텍스트 동일 라인

<?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="55dip" 
    android:orientation="horizontal" 
    android:weightSum="1" > 

<TextView 
    android:id="@+id/listItem" 
    android:layout_width="match_parent" 
    android:layout_height="35dp" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:gravity="center_vertical" 
    android:layout_weight="0.2" 
    android:textSize="17dip" 
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" /> 

<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:layout_weight="0.8" 
    android:textSize="8dp" 
    android:singleLine="true" 
    android:text="Assign Badge" 
    android:id="@+id/assign" /> 

</LinearLayout> 
+0

'width'는'weight'를 사용하기 때문에''0dp ''이어야합니다. – codeMagic

답변

2

참조입니다

android:paddingLeft="xxdip" 
    android:paddingRight="xxdip" 

,

<?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="55dip" 
android:orientation="horizontal" > 
<TextView 
    android:id="@+id/listItem" 
    android:layout_width="0dp" 
    android:layout_height="35dp" 
    android:layout_weight="0.7" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:gravity="center_vertical" 
    android:text="TEST" 
    android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" 
    android:textSize="17dip" /> 

<Button 
    android:id="@+id/assign" 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.3" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:singleLine="true" 
    android:text="Assign Badge" 
    android:textSize="8dp" /> 
</LinearLayout> 
+0

고맙습니다. 고맙습니다. –

0

당신은 패딩 사용할 수 있습니다 xx는이 도움이 경우 값

0

당신이 확인하려면 당신의 넓은 당신은을 수정할 수 있습니다 두 요소의 가중치.

가중치를 사용하면 너비를 고려한 두 요소 사이의 간격이 자동으로 분배됩니다. 안드로이드의 weight 속성은 카운터 직관적으로 작동하는 것처럼 보입니다 (더 큰 가중치를 가진 요소가 더 작은 공간을 차지함). 이 원하는 결과를 이끌어 넥서스 5를 사용하여 내 테스트에서

는 :

하지만 당신의 LinearLayout에

[...] 
<LinearLayout 
    [...] 

    <TextView 
     [...] 
     android:id="@+id/listItem" 
     android:layout_weight="0.3" /> 

    <Button 
     [...] 
     android:layout_weight="0.7" 
     android:id="@+id/assign" /> 

</LinearLayout> 

참고 weight_sum 요소 (I은 읽기 쉽도록 변경되지 않은 코드를 왼쪽). 가중치가이 숫자에 더해지지 않으면 레이아웃은 레이아웃보다 작거나 커집니다. 속성을 제거하면 요소가 레이아웃에서 사용 가능한 모든 공간을 차지합니다.