2016-01-28 52 views
-1

我將動態添加RatingBar爲線性佈局。評分欄在手機中不可見,因爲它在平板電腦中可見。 以下是創建RatingBar的代碼。動態添加RatingBar不顯示

View newWidget = new RatingBar(appContext); 
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
       ViewGroup.LayoutParams.WRAP_CONTENT); 
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL; 
    newWidget.setLayoutParams(layoutParams); 
    ((RatingBar) newWidget).setStepSize(1.0f); 
+0

你還沒有添加布局參數來查看 –

+0

忘了添加那件作品@VivekMishra –

回答

0

試試下面的代碼:

RatingBar ratingBar = new RatingBar(context, null, android.R.attr.ratingBarStyleSmall); 

嘗試加載其視圖運行之前設置的評價欄樣式。我希望它能爲你工作。謝謝!!!

+0

當我設置樣式爲android.R.attr.ratingBarStyleSmall但它不起作用如果樣式設置爲android.R.attr .ratingBarStyle。我不想要小部件 –

+0

好吧,嘗試用你自己的風格評級吧。 –

相關問題