2017-05-26 68 views
0

我與它垂直的LinearLayout一個Horizo​​ntalScrollView。在那裏我添加了一些相同類型的自定義視圖。默認情況下視圖之間有很多間距。所以我猜我有我的觀點邊距設置爲0或東西。但絕對沒有結果。
首先,我試圖改變保證金的XML很多意見和利潤率之間的間距沒有做的東西

<gui.CardUi 
    android:id="@+id/cardUi" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_margin="0dp" 
    </gui.CardUi> 

比我試了一下改變保證金代碼:

如果
private void setMargins (int left, int top, int right, int bottom) { 
    if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { 
     ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) getLayoutParams(); 
     p.setMargins(left, top, right, bottom); 
     requestLayout(); 
    } 
    } 

setMargins(0, 0, 0, 0); 

不知道的信息是重要的,但我想補充編程的意見與LayoutInflater。

回答

1

你的利潤率將不會因爲你吹的意見的方式進行設置。 我猜你用這樣的方式:

View child = getLayoutInflater().inflate(R.layout.mylayout, null); 

的一點是,當你想誇大一個視圖,並把它添加到另一種觀點認爲,應通知有關容器視圖充氣(在你的例子線性佈局)。因此,您的佈局參數(如邊距和重量以及重力)將被正確設置。

View child = getLayoutInflater().inflate(R.layout.child, item, false); 

沒有必要在代碼中添加保證金: 所以用這個方法來代替。

+0

這幫助我。謝啦 – MolteNolte