我一直在試圖添加視圖在我的LinearLayout
誰的方向是HORIZONTAL
。LinearLayout的addView不顯示
This LinearLayout
is in CoordinatorLayout
,NestedScrollView
and end HorizontalScrollView
。這是結構 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<mycustom..FlingNestedScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="vertical">
.
.
.
<RelativeLayout
android:id="@+id/online_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingStart="20dp">
<mycustom..FontTextView
android:id="@+id/lbl_available"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="@string/available_sizes"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textSize="@dimen/product_detail_available_font_size"
app:customFont="@string/font_circular_medium" />
<HorizontalScrollView
android:id="@+id/horizontal_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/lbl_available"
android:scrollbars="none">
<LinearLayout
android:id="@+id/ll_sizes"
android:layout_width="match_parent"
android:layout_height="7dp"
android:orientation="horizontal"
android:paddingBottom="@dimen/product_detail_sizes_padding_bottom" />
</HorizontalScrollView>
</RelativeLayout>
.
.
.
</LinearLayout>
</mycustom..FlingNestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/windowBackground"
android:fitsSystemWindows="true"
app:expanded="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="?attr/colorPrimaryDark">
.
.
.
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
.
.
.
</android.support.design.widget.CoordinatorLayout>
在我Activity
我用下面的代碼,一旦我在我的UI線程獲取數據 -
@BindView(R.id.online_size) View onlineSizes;
@BindView(R.id.ll_sizes) LinearLayout llSizes;
private void displaySizes() {
onlineSizes.setVisibility(View.VISIBLE);
if (llSizes.getChildCount() <= 0) {
for (int i = 0; i < mPresenter.getSizeArrayList().size(); i++) {
FontTextView label = (FontTextView) LayoutInflater.from(getActivityContext()).inflate(R.layout.listitem_label_size_element, null);
label.setText(mPresenter.getSizeArrayList().get(i));
View view = LayoutInflater.from(getActivityContext()).inflate(R.layout.listitem_image_size_element, null);
llSizes.addView(label);
if (i != mPresenter.getSizeArrayList().size() - 1)
llSizes.addView(view);
}
}
}
內部佈局 listitem_label_size_element.xml
<?xml version="1.0" encoding="utf-8"?>
<mycustom..FontTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lbl_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/product_detail_sizes_intermediate_padding_right"
android:layout_marginRight="@dimen/product_detail_sizes_intermediate_padding_right"
android:gravity="center_vertical"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/product_detail_sizes_font_size"
app:customFont="@string/font_ss_regular" />
和listitem_image_size_element.xml
是
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/img_dot"
android:layout_width="5dp"
android:layout_height="5dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/product_detail_sizes_intermediate_padding_right"
android:layout_marginRight="@dimen/product_detail_sizes_intermediate_padding_right"
android:adjustViewBounds="true"
android:gravity="center_vertical"
android:scaleType="fitXY"
android:src="@drawable/dot" />
獲取數據後,我調試了代碼並檢查了llSizes
有10 mChildCount
但仍然沒有顯示。
PS:把它變成重複線程之前,我已經測試了以下東西 -
llSize.invalidate();
llSize.notify();
LayoutInflater.from(getActivityContext()).inflate(R.layout.listitem_label_size_element, llSizes, false);
LayoutInflater.from(getActivityContext()).inflate(R.layout.listitem_image_size_element, llSizes, false);
不停whol e方法displaySizes()
到llSizes.postDelayed()
延遲100毫秒。
現在除了這個,我不知道我錯過了什麼。
認真地有人必須使其今天有目的的消極。哇!!! –