2014-04-05 3 views
1

내 모든 스타일을 변경하려고하지만 어떤 이유로 내 스타일이 여백에 영향을 미치지 않습니다. (그들은 서로 바로 옆에 나타납니다) 그러나 layout.xml에서 layout_margin을 바꿔도 작동합니다.버튼의 layout_margin을 스타일에서 변경할 수 없습니까?

이 내 코드입니다 :

<style name="Button" parent="@android:style/Widget.DeviceDefault.Button"> 
    <item name="android:layout_margin">5dp</item> 
    <item name="android:background">@android:color/holo_orange_light</item> 
</style> 

이 내 레이아웃입니다 : 내가 잘못 뭐하는 거지

<TableRow 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:baselineAligned="false" 
    android:clickable="false" 
    android:layout_height="fill_parent" 
    android:layout_width="match_parent"> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="1" 
     android:id="@+id/button1" 
     android:layout_weight="0.06" 
     android:clickable="true" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="2" 
     android:id="@+id/button2" 
     android:layout_weight="0.06" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="3" 
     android:id="@+id/button3" 
     android:layout_weight="0.06" 
     android:layout_marginBottom="2dp" // This works 
     android:layout_marginTop="2dp" /> 

</TableRow> 
//... 

? 난 그냥 같은 문제이고 이런 모든 레이아웃의 모든 버튼 스타일을 정의하는 여백 솔루션에 직면했다

+0

layout.xml을 질문에 추가하십시오. –

+0

방금 ​​추가했습니다. 덕분에 – lisovaccaro

+0

이 경우에는 내가 가로 선형 레이아웃 문제에있는 모든 버튼을 넣어 해결할 수 있지만, 나는 비슷한 레이아웃을 사용하여 구현하려고 TableLayout와 비슷한 이상한 문제가 있었어. –

답변

0

: 그래서

<TableRow 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:baselineAligned="false" 
    android:clickable="false" 
    android:layout_height="fill_parent" 
    android:layout_width="match_parent"> 

    <Button 
     style="@style/Button" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="1" 
     android:id="@+id/button1" 
     android:layout_weight="0.06" 
     android:clickable="true" /> 

    <Button 
     style="@style/Button" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="2" 
     android:id="@+id/button2" 
     android:layout_weight="0.06" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:text="3" 
     android:id="@+id/button3" 
     android:layout_weight="0.06" 
     android:layout_marginBottom="2dp" // This works 
     android:layout_marginTop="2dp" /> 
</TableRow> 
//... 

을, 당신도에서 테마에 추가 할 필요가 없습니다 이 경우.

출처 : https://stackoverflow.com/a/13365288/3564556

관련 문제