我一直在尝试在我LinearLayout
HORIZONTAL
的方向中添加观看次数。
此LinearLayout
位于CoordinatorLayout
,NestedScrollView
以及最后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:在将它放入Duplicate线程之前,我已经测试了以下内容 -
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);
将整个方法displaySizes()
保存到llSizes.postDelayed()
,延迟时间为100毫秒。
现在除此之外,我不确定我错过了什么。
答案 0 :(得分:1)
这是因为您已将布局高度设置为7dp
。设为wrap_content
并为其设置最小或最大高度,然后就可以了。