0
我知道這已經被問過,但我想一切,我沒能解決我的問題。addView增加了看法,但它沒有顯示它
當我編程方式創建這個觀點,他們肯定是增加,我檢查在調試器,一切都在它的地方,即使父視圖獲取的更大的高度,因爲他們使用的空間。但我看不到他們,就像他們低於其他觀點或看不見(但他們不是,我檢查了很多次......)。
這就是我想要插入的意見的XML代碼,我想將它們插入光標所在(在那裏的標籤信息)。我只是在那裏向你展示它最終的樣子,但這部分將以編程方式添加。
<LinearLayout
android:id="@+id/llhTestItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvInformationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
fontPath="fonts/OpenSans-Regular.ttf"
android:text="Sub title: "/> <!-- tvInformationTitle -->
<TextView
android:id="@+id/tvInformation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
fontPath="fonts/OpenSans-Light.ttf"
android:text="information"/> <!-- tvInformation -->
</LinearLayout> <!-- information -->
下面你可以看到我用來添加視圖的代碼,就像上面的xml一樣。
@Override
public void onBindViewHolder(SetupViewerHolder holder, int position) {
CardViewItem cardViewItem = cardViewItemList.get(position);
holder.tvTitle.setText(cardViewItem.getCardTitle());
for (int i = 0; i < cardViewItem.getInformationList().size(); i++){
//region Create llhItem
LinearLayout.LayoutParams llhItemParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
llhItemParams.topMargin = dipToPixels(6);
LinearLayout llhItem = new LinearLayout(context);
llhItem.setLayoutParams(llhItemParams);
llhItem.setOrientation(LinearLayout.HORIZONTAL);
//endregion
LinearLayout.LayoutParams tvInformationsParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
//region Create tvInformationTitle
TextView tvInformationTitle = new TextView(context);
tvInformationTitle.setLayoutParams(tvInformationsParams);
tvInformationTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
if (Build.VERSION.SDK_INT < 23){
tvInformationTitle.setTextAppearance(context, R.style.OpenSansRegular);
} else {
tvInformationTitle.setTextAppearance(R.style.OpenSansRegular);
}
tvInformationTitle.setText(cardViewItem.getInformationList().get(i)[0]);
//endregion
//region Create tvInformation
TextView tvInformation = new TextView(context);
tvInformation.setLayoutParams(tvInformationsParams);
tvInformation.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
if (Build.VERSION.SDK_INT < 23){
tvInformation.setTextAppearance(context, R.style.OpenSansLight);
} else {
tvInformation.setTextAppearance(R.style.OpenSansLight);
}
tvInformation.setText(cardViewItem.getInformationList().get(i)[1]);
//endregion
llhItem.addView(tvInformationTitle);
llhItem.addView(tvInformation);
holder.llvInformation.addView(llhItem);
}
基本上我試圖實現是有一個回收視圖,並且每個項目只有一個標題,一個溢出按鈕,但可以有多個信息行。 這裏是一個打印的,這是我以前在xml中用硬編碼作爲原型。
我知道這樣做可能工作的一些替代辦法,但現在我想有它這樣的,因爲一切工作像它應該,意見只是「不可見」 。
我試過了,沒錯。 –
我不知道佈局參數是否有問題。至少llhItem本身是可見的?例如,如果你爲它設置了一個bg顏色,你能看到它嗎? – George
設置一個bg工作,然後我意識到由於某種原因,如果我沒有爲它設置顏色,文本是不可見的。非常感謝 !難以置信,最後總是有些簡單...... :) –