2014-09-25 6 views
0

이것은 현재 레이아웃입니다. 내가 권유로텍스트보기가 내 레이아웃의 단추보다 약간 더 많은 공간을 차지하도록 만드는 방법은 무엇입니까?

enter image description here

그리고 내 현재의 레이아웃 코드는

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/transparent" > 

<TextView 
    android:id="@+id/stockView" 
    android:text="TextView" 
    android:layout_weight="1" /> 

<Button 
    android:id="@+id/stockQuote" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/get_stock_quote" 
     android:layout_weight="1" /> 

<Button 
    android:id="@+id/webStock" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/go_to_website" 
     android:layout_weight="1" /> 

</TableRow> 

모든 것은 내가 각 요소를 "1"의 layout_width를 주었기 때문에, 그들은 동일한 양의 공간을 차지한다는, 미세 운동한다 테이블 행에. 그러나 텍스트보기에서 단추보다 많은 공간을 차지하여 텍스트보기의 layout_weight를 2로 변경하여 각 단추가 단추의 1/4을 차지하는 동안 추가 공간의 절반을 차지할 수있게하려고합니다. 이 변경을 한 후에, 이것이 내가 레이아웃에 대해 얻은 것입니다. enter image description here

왜 이런 일이 일어 났는지 이해할 수 있습니까? 텍스트보기는 지금도 보이지 않습니다. 어떻게하면 텍스트보기가 좀 더 많은 공간을 차지하도록 고칠 수 있습니까?

+0

"layout_ * width *"라고 말하면 "layout_ * weight *"를 의미합니까? – aij

+0

당신은'TableRow'의'weightSum'을'4'로 설정 한 다음 원하는 값'(2, 1, 1)'을 사용할 수 있습니다. 더 정확한 크기 관계를 위해'layout_weight'에 부동 소수점 값을 사용할 수도 있습니다. – nem035

+0

이전에 무게 합계는 얼마입니까? TableRows에서만 사용합니까? – committedandroider

답변

1

weightSum 최대 무게 합계를 정의합니다. 지정되어 있지 않은 경우, 합계는 모든 아이의 layout_weight를 추가해 계산됩니다.

<TableRow android:weightSum="1"> 
<TextView 
    android:id="@+id/stockView" 
    android:text="TextView" 
    android:layout_weight="0.5" /> 

<Button 
    android:id="@+id/stockQuote" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/get_stock_quote" 
     android:layout_weight="0.25" /> 

<Button 
    android:id="@+id/webStock" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/go_to_website" 
     android:layout_weight="0.25" /> 
</TableRow> 

here

+0

고마워요. – committedandroider

+0

코드가 정상적으로 작동하는 것으로 나타났습니다. 미리보기가 조금 벗어났습니다. – committedandroider

1

weightSum = TOTAL (100 %)

에 layout_weight = %

이 시도에 대해 당신은 자세한 내용을보실 수 있습니다 : 당신이하려고

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@android:color/transparent" 
android:weightSum="100"> 

<TextView 
    android:id="@+id/stockView" 
    android:text="TextView" 
    android:layout_weight="40" /> 

<Button 
    android:id="@+id/stockQuote" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/get_stock_quote" 
     android:layout_weight="30" /> 

<Button 
    android:id="@+id/webStock" 
    style="?android:attr/buttonStyleSmall" 
    android:text="@string/go_to_website" 
     android:layout_weight="30" /> 

</TableRow> 
0

을 당신이해야 할 전체 파티션 비율을 제공하십시오

예 : 당신은 3 화면의 폭을 분할 싶다면 다음 weightSum 3이어야하며, 분할 비율은 당신이 개별적으로

아래는 샘플 코드는 다음을 시도하십시오있는 모든보기를 제공해야합니다

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:background="@android:color/transparent" 
    android:weightSum="1" > 

    <TextView 
     android:id="@+id/stockView" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:text="TextView" 
     android:layout_weight="0.5" /> 

    <Button 
     android:id="@+id/stockQuote" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"    
     style="?android:attr/buttonStyleSmall" 
     android:text="@string/get_stock_quote" 
     android:layout_weight="0.25" /> 

    <Button 
     android:id="@+id/webStock" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content"    
     style="?android:attr/buttonStyleSmall" 
     android:text="@string/go_to_website" 
     android:layout_weight="0.25" /> 

</TableRow>