2012-03-21 117 views
1

這與我的previous question類似,但它不適用於Kindle Fire(2.3.4)。
我使用FragmentTransaction將一個片段添加到FrameLayout中。我想動態地改變片段使用的RelativeLayout的邊距。在RelativeLayout上設置頁邊距在Kindle Fire上不起作用

但是,Kindle Fire上的FrameLayout.layoutParams的邊距沒有變化。但是,這適用於3.2.1。我也嘗試使用setMargins(),它沒有工作。

有誰知道我如何動態地改變Kindle Fire的邊距?

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.infocard, container, false); 

     RelativeLayout infoLayout = (RelativeLayout) view.findViewById(R.id.info); 
     infoLayout.setOnClickListener(new EmptyClickListener()); 

     final int width = 250; 
     final int height = 270; 
     int leftMargin = 0; 
     int topMargin = 0; 
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height); 

     if (x - width < 0) { 
      leftMargin = 0; 
     } else { 
      leftMargin = x - width + 40; 
     } 

     if (y >= 400 && y <= 480) { 
      topMargin = 160; 
     } 

     params.leftMargin = leftMargin; 
     params.topMargin = topMargin; 

     //params.setMargins(leftMargin, topMargin, 0, 0); //this didnt work either 
     infoLayout.setLayoutParams(params); 

     TextView titleView = (TextView) view.findViewById(R.id.titleCard); 
     titleView.setText(title); 

     return view; 
    } 
+0

是infoLayout一個FrameLayout裏或RelativeLayout的的子視圖? – 2012-03-22 00:04:59

+0

infoLayout是一個RelativeLayout – heero 2012-03-22 00:08:25

+0

爲什麼使用FrameLayout.LayoutParams代替RelativeLayout.LayoutParams?你有沒有嘗試過使用RelativeLayout.LayoutParams?更重要的是,你有沒有嘗試調用params = infoLayout.getParams();然後編輯參數而不是重新創建它們? – 2012-03-22 00:15:57

回答

3

好吧,我能夠在另一RelativeLayout的包裝我infoLayout來解決這個問題,而現在它完美