2013-12-10 57 views
0

我在裏面有一個LinearLayout和一些Views查看忽略佈局的形狀

LinearLayout有以下背景抽拉:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item > 
    <shape 
     android:shape="rectangle"> 
    <solid android:color="#25000000" /> 
    <corners android:radius="5dp"/> 
    </shape> 
</item> 
<item android:right="1dp" android:left="1dp" android:bottom="2dp"> 
    <shape 
     android:shape="rectangle"> 
    <solid android:color="@android:color/white"/> 
    <corners android:radius="5dp"/> 
    </shape> 
</item> 

所以我的佈局有一定的圓角。

現在我喜歡在我的LinearLayout中設置我的視圖的背景顏色,這裏是問題: 背景不在形狀內......它忽略了我的LinearLayout中的拐角半徑。視圖應該堅持與LinearLayout具有相同的大小。不應該有什麼「超過」這種佈局。

我該如何管理?我不希望同樣的背景抽拉(相同的形狀)適用於我查看......我想這不是我應該做這樣的方式......

乾杯

佈局:

<TableLayout 
    android:id="@+id/table_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"  
    android:stretchColumns="*"> 
</TableLayout> 

我編程添加視圖(它們屬於片段):

FragmentTransaction transaction = getChildFragmentManager() 
      .beginTransaction(); 
for (int i = 0; i < answers.size(); i++) { 
    TableRow row = tableRows.get(i % tableRows.size()); 
    AnswerFragment fragment = answers.get(i).getViewFragment(); 
    answerFragments.add(fragment); 
    transaction.add(row.getId(), fragment); 
} 
transaction.commit(); 

,其中,通過創建tableRows:

int rows = (int) Math.ceil(Math.sqrt(answers.size())); // n x n 
for (int i = 0; i < rows; i++) { 
TableRow row = new TableRow(getActivity()); 
row.setId(1337 + i); 
row.setLayoutParams(new TableLayout.LayoutParams(
     TableLayout.LayoutParams.MATCH_PARENT, 
     TableLayout.LayoutParams.MATCH_PARENT, 1.0f)); 
row.setGravity(Gravity.CENTER); 
tableRows.add(row); 
tableLayout.addView(row); 
} 
+0

發佈您的佈局代碼。 – zanky

回答

0

使用填充或邊距將您的視圖放置在LinearLayout中,就像您需要它一樣。

+0

嘿,對不起,這不是我想要的。我的意見背景應該符合佈局。如果佈局具有圓角,則我的佈局的視圖也應該有圓角...... – Frame91

+0

然後,您還需要將圓角應用於LinearLayout中的每個視圖。 LinearLayout的背景與放置在其中的兒童視圖的背景無關。這兩個人是獨立的。 –

+0

雖然這真的很複雜,但我必須檢查視圖是位於網格的一側還是中間......因爲每行的第一個和最後一個元素都會受到影響......並且如果我更改佈局的可繪製的,我將不得不改變子元素的佈局...這看起來不正確... – Frame91