ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – Spinner在选择项目后向下移动布局

2019-07-06 16:23:38  阅读:165  来源: 互联网

标签:android android-layout android-spinner


我有一个奇怪的问题.我在布局中添加了一个微调器.当我在微调器中选择一个项目时,微调器在布局中向下移动,导致页面中的垂直滚动.我不希望发生这种情况,因为这会导致我的页面上的按钮在滚动之前显示在屏幕上较少.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="20dp"
android:paddingRight="20dp" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingTop="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/id_gwp_configuration_productImage"
            android:layout_width="@dimen/product_collections_image_width"
            android:layout_height="@dimen/product_collections_image_height"
            android:scaleType="fitXY" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="10dp" >

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
                android:id="@+id/id_gwp_configuration_titleTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:ellipsize="end"
                android:lineSpacingExtra="8dp"
                android:maxLines="3"
                android:paddingBottom="4dp"
                android:singleLine="false"
                android:text="@string/pdp_title"
                android:textColor="@android:color/black"
                android:textSize="12sp" />

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
                android:id="@+id/id_gwp_configuration_salePriceTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="5dp"
                android:text="@string/pdp_sale_price"
                android:textColor="@color/pdp_red_sale_price"
                android:textSize="18sp"
                android:textStyle="bold" />

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
                android:id="@+id/id_gwp_configuration_regularPriceTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:text="@string/pdp_regular_price"
                android:textColor="@color/pdp_grey_original_price"
                android:textSize="12sp" />

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
                android:id="@+id/id_gwp_configuration_skuCodeTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="10dp"
                android:text="@string/pdp_regular_price"
                android:textColor="@color/pdp_grey_original_price"
                android:textSize="12sp" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
    android:id="@+id/id_gwp_configuration_offerTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:maxLines="2"
    android:paddingBottom="20dp"
    android:textColor="@color/pdp_green_offer"
    android:textSize="12sp"
    android:visibility="gone" />

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
    android:id="@+id/id_gwp_configuration_short_description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:lineSpacingExtra="8dp"
    android:maxLines="2"
    android:text="Description text"
    android:textSize="12sp" />

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
    android:id="@+id/id_gwp_configuration_show_more"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="@string/show_more"
    android:textColor="@android:color/holo_blue_bright"
    android:textSize="12sp" />

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
    android:id="@+id/id_gwp_configuration_long_descTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:lineSpacingExtra="8dp"
    android:text="Description text"
    android:textSize="12sp"
    android:visibility="gone" />

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
    android:id="@+id/id_gwp_configuration_show_less"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:text="@string/show_less"
    android:textColor="@android:color/holo_blue_bright"
    android:textSize="12sp"
    android:visibility="gone" />

<include
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/product_details_swatch_images" />

<LinearLayout
    android:id="@+id/id_gwp_configuration_swatchShowLessLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone" >

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@drawable/product_detail_black_divider" />

    <com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
        android:id="@+id/id_gwp_configuration_swatchShowLessTxt"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:background="@android:color/white"
        android:gravity="center_horizontal|center_vertical"
        android:text="@string/pdp_show_fewer_colors"
        android:textColor="@android:color/black"
        android:textSize="12sp"
        android:textStyle="bold" />
</LinearLayout>

<LinearLayout
    android:id="@+id/id_gwp_configuration_sizeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="4dp"
    android:visibility="gone" >

    <Spinner
        android:id="@+id/id_gwp_configuration_sizeSpinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp" />

    <LinearLayout
        android:id="@+id/id_gwp_configuration_sizeGuideLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
            android:id="@+id/id_gwp_configuration_sizeNotSureTxt"
            style="bold"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_vertical"
            android:text="@string/pdp_not_sure_about_size"
            android:textColor="@android:color/black"
            android:textSize="12sp"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
                android:id="@+id/id_gwp_configuration_sizeCheckOutTxt"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:text="@string/pdp_check_out_guide"
                android:textColor="@android:color/black"
                android:textSize="12sp" />

            <com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
                android:id="@+id/id_gwp_configuration_sizeGuide"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:textColor="@android:color/black"
                android:textSize="12sp" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBookTextView
    android:id="@+id/id_gwp_configuration_quantityTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="4dp"
    android:paddingTop="12dp"
    android:text="@string/pdp_quantity"
    android:textColor="@android:color/black"
    android:textSize="12sp"
    android:visibility="gone" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="4dp" >

    <Button
        android:id="@+id/id_gwp_configuration_qtyDownBtn"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="@drawable/product_detail_black_border"
        android:text="@string/pdp_qty_minus"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:visibility="gone" />

    <EditText
        android:id="@+id/id_gwp_configuration_qtyValue"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="@drawable/product_detail_black_border"
        android:gravity="center"
        android:inputType="number"
        android:text="1"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:visibility="gone" />

    <Button
        android:id="@+id/id_gwp_configuration_qtyUpBtn"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="@drawable/product_detail_black_border"
        android:text="@string/pdp_qty_plus"
        android:textColor="@android:color/black"
        android:textSize="20sp"
        android:visibility="gone" />

    <com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldButton
        android:id="@+id/id_gwp_configuration_addGiftToBagBtn"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_gravity="center"
        android:background="@color/pdp_add_to_bag_disable"
        android:text="@string/gwp_add_gift_to_bag"
        android:textColor="@android:color/white"
        android:textSize="12sp" />
</LinearLayout>

<com.kohls.mcommerce.opal.framework.view.component.views.GothamBoldTextView
    android:id="@+id/id_gwp_configuration_removeGift"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:gravity="center"
    android:paddingBottom="4dp"
    android:text="@string/pdp_remove_gift"
    android:textColor="@android:color/black"
    android:textSize="12sp"
    android:visibility="gone" />

 

这里我在代码中使用微调器

/**
 * Set spinner to display size of the mProduct.
 */
private void setProductSizeSpinner() {

    if (mProduct != null) {
        List<String> sizeList = new ArrayList<String>();

        if (mProduct.getSKUS() != null) {
            ArrayList<String> sizeListSet = null;
            PriceColor priceColor = new PriceColor();
            if (mSelectedColor == null) {
                if (!mColorToSizeMap.isEmpty()) {
                    Iterator<Entry<PriceColor, ArrayList<String>>> enteries = mColorToSizeMap.entries();
                    if (enteries.hasNext()) {
                        Entry<PriceColor, ArrayList<String>> entry = enteries.next();
                        priceColor = entry.getKey();
                        if (entry.getKey() != null) {
                            mSelectedColor = entry.getKey().color;
                        } else {
                            mSelectedColor = new String();
                        }
                        sizeListSet = entry.getValue();
                        mIsColorRequired = true;
                        mSwatchColorNameLayout.setVisibility(View.VISIBLE);
                        mTextSwatchColorName.setText(" " + mSelectedColor);
                    }
                }
            } else {
                com.kohls.mcommerce.opal.common.util.Logger.debug("ProductDetails",
                        "Price : " + mSelectedPrice);
                if (mSelectedPrice == null || mSelectedPrice.equalsIgnoreCase("")) {
                    priceColor.price = getSKUPrice(mSku);
                } else {
                    priceColor.price = mSelectedPrice;
                }
                priceColor.color = mSelectedColor;
                if (mSwatchImagesList != null && !mSwatchImagesList.isEmpty()) {
                    sizeListSet = mColorToSizeMap.getValue(priceColor);
                } else if (!mColorToSizeMap.isEmpty()) {
                    Collection<ArrayList<String>> allSizesList = mColorToSizeMap.getAllValues();
                    sizeListSet = new ArrayList<String>();
                    for (ArrayList<String> newSizesList : allSizesList) {
                        sizeListSet.addAll(newSizesList);
                    }
                }
            }

            if (mCrossedColorsIds != null && !mCrossedColorsIds.isEmpty()) {
                clearCrossedSwatchImages();
            }
            if (sizeListSet != null) {
                sizeList = removeOutofStockSizes(sizeListSet, priceColor);
            }
            if (sizeList != null && sizeList.size() > 0) {
                mIsSizeRequired = true;
                sizeList.add(0, mContext.getString(R.string.pdp_select_size));

                mSpinnerProductSizeLayout.setVisibility(View.VISIBLE);
                mSpinnerProductSize.setVisibility(View.VISIBLE);
                dropDownAdapterSize = new ArrayAdapter<String>(mContext,
                        R.layout.spinner_text_view,
                        sizeList) {

                    @Override
                    public View
                            getDropDownView(int position, View convertView, ViewGroup parent) {

                        View view = null;

                        TextView textSize = new TextView(getContext());

                        if (position == 0) {
                            textSize.setHeight(0);
                            textSize.setVisibility(View.GONE);
                            view = textSize;
                        } else {
                            // Pass convertView as null to prevent
                            // reuse of special case views
                            view = super.getDropDownView(position, null, parent);
                        }
                        return view;
                    }
                };

                mSpinnerProductSize.setAdapter(dropDownAdapterSize);

                // Select last selected value of size.
                if (mSelectedSize != null && mSkuMap.size() > 1) {
                    int spinnerPosition = dropDownAdapterSize.getPosition(mSelectedSize);
                    if (spinnerPosition == -1) {
                        mSpinnerProductSize.setSelection(0);
                        mIsSizeRequired = false;
                        mSelectedSize = null;
                        setButtonState(false);
                    } else {
                        mSpinnerProductSize.setSelection(spinnerPosition);
                    }
                }
                mSpinnerProductSize.setOnItemSelectedListener(mSizeSpinnerItemSelectedListener);
            } else {
                mIsSizeRequired = false;
                mSpinnerProductSize.setSelection(0);
                mSpinnerProductSize.setVisibility(View.INVISIBLE);
            }
        }
    }
}

https://www.dropbox.com/s/50xw0szs96c8ql0/Screenshot_2015-09-05-14-40-17.png?dl=0

https://www.dropbox.com/s/e8x066r9e4iz3mu/Screenshot_2015-09-05-14-42-48.png?dl=0

正如您在上面的屏幕截图中看到的那样,我指的是“添加礼物到包”按钮被隐藏.

解决方法:

你只需要指定微调器的高度,

标签:android,android-layout,android-spinner
来源: https://codeday.me/bug/20190706/1398796.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有