I have the following part of an XML file -
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activity_product_page_top_product_layout">
<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_product_page_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/activity_product_page_nested_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/marketplace_padding_15dp">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/very_light_grey" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/activity_product_page_brands_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginLeft="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:fontFamily="@font/noto_sans"
android:text="@string/breadcrumbs_brands"
android:textStyle="bold" />
<TextView
android:id="@+id/activity_product_page_vendor_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_toEndOf="@id/activity_product_page_brands_breadcrumbs"
android:layout_toRightOf="@id/activity_product_page_brands_breadcrumbs"
android:fontFamily="@font/noto_sans"
android:text="@string/products_breadcrumbs_unknown_vendor"
android:textStyle="bold" />
<TextView
android:id="@+id/activity_product_page_product_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_toEndOf="@id/activity_product_page_vendor_breadcrumbs"
android:layout_toRightOf="@id/activity_product_page_vendor_breadcrumbs"
android:ellipsize="end"
android:fontFamily="@font/noto_sans"
android:maxLines="1"
android:text="@string/activity_product_page_unknown_product"
android:textColor="#979797" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:background="@color/very_light_grey" />
<android.support.v4.view.ViewPager
android:id="@+id/activity_product_page_view_pager"
android:layout_width="match_parent"
android:layout_height="300dp"
android:paddingStart="40dp"
android:paddingLeft="40dp"
android:paddingEnd="40dp"
android:paddingRight="40dp"
tools:layout_height="300dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:background="@color/very_light_grey"
android:orientation="vertical">
<TextView
android:id="@+id/activity_product_page_product_title_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:textSize="20sp"
android:textStyle="bold"
tools:text="Products long title" />
<TextView
android:id="@+id/activity_product_page_product_short_description_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
tools:text="Product short description" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp">
<TextView
android:id="@+id/activity_product_page_sold_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_sold_by" />
<TextView
android:id="@+id/activity_product_page_vendors_name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/activity_product_page_sold_by"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_toEndOf="@+id/activity_product_page_sold_by"
android:layout_toRightOf="@+id/activity_product_page_sold_by"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textStyle="bold"
tools:text="Vendors name, " />
<TextView
android:id="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_product_page_vendors_name_textview"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_fulfilled_by" />
<TextView
android:id="@+id/activity_product_page_fulfilled_by_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_toEndOf="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:layout_toRightOf="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textStyle="bold"
tools:text="Project Verte." />
<TextView
android:id="@+id/activity_product_page_sku_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_sku_unknown"
tools:text="SKU: K004" />
</RelativeLayout>
<TextView
android:id="@+id/activity_product_page_product_price_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_fetching_price"
android:textSize="20sp"
android:textStyle="bold"
tools:text="$35.00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_additional_tax_may_apply_on_checkout" />
<RelativeLayout
android:id="@+id/activity_product_page_availability_view_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_padding_15dp">
<TextView
android:id="@+id/activity_product_page_availability_hardcoded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_availability" />
<TextView
android:id="@+id/activity_product_page_availability_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/activity_product_page_availability_hardcoded"
android:layout_toEndOf="@+id/activity_product_page_availability_hardcoded"
android:layout_toRightOf="@+id/activity_product_page_availability_hardcoded"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textColor="@color/red_delete"
tools:text="Out of stock" />
</RelativeLayout>
<!-- This is where I want to add the dynamic views -->
<Button
android:id="@+id/activity_product_page_add_to_cart_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:background="@color/color_black"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_add_to_cart"
android:textColor="@color/white" />
<Button
android:id="@+id/activity_product_page_buy_now_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:background="@color/color_black"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_buy_now"
android:textColor="@color/white" />
<TextView
android:id="@+id/activity_product_page_share_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_share" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_related_products"
android:textSize="22sp"
android:textStyle="bold" />
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_product_page_related_recycleview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
tools:listitem="@layout/fragment_marketplace_products_row_item" />
<View
android:id="@+id/activity_product_page_bottom_view"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="@dimen/marketplace_padding_15dp"
android:layout_marginBottom="60dp"
android:background="@color/light_black"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
which looks like this -
What I want to achieve is below the "availability" textview I want to add textviews that display information the same way as the availability does.
What I have tried so far -
for (String key : selectedProductAttributesMap.keySet()) {
TextView textView = new TextView(this);
textView.setText(key);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(14,15,14,0);
textView.setLayoutParams(params);
nestedLinearLayout.addView(textView);
}
It create the views down below at the bottom of the linear layout, so I am missing the option to put it at a specific place. How can I do that?
Add a
LinearLayout
where you have your comment<!-- This is where I want to add the dynamic views -->
and add the TextViews inside thatViewGroup
, instead ofnestedLinearLayout
As for
you can call
addView
with a secondint
parameter which is the index where you want the view inserted