小编ziL*_*iLk的帖子

scrollBy在嵌套的recyclerview中无法正常工作

我有一个垂直滚动RecyclerView与水平滚动内部RecyclerViews就像这样.

EXPL

通过此实现,用户可以同步滚动每个水平回收站视图.但是,当用户垂直滚动到父级recyclelerView时,刚刚附加在窗口上的新水平回收视图不会显示在同一滚动x位置上.这个是正常的.因为它刚刚创建.

所以,我曾试图在显示之前滚动到滚动位置.像这样:

注意:这是在父回收者视图的适配器中,其方向是垂直的.

 @Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        CellColumnViewHolder viewHolder = (CellColumnViewHolder) holder;
        if (m_nXPosition != 0) {
             // this doesn't work properly 
             viewHolder.m_jRecyclerView.scrollBy(m_nXPosition, 0);
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

正如您所看到的,scrollBy第10行,第11行,第12行第13 没有影响.之后,我调试了代码,以便找出发生了什么.当我使用scrollBy设置滚动位置时,childCount()为第10 ,第11 ,第12 第13 返回零,因此它们不会滚动.但为什么 ?为什么其他人工作?

  • 我怎样才能解决这个问题 ?
  • 是onViewAttachedToWindow正确的位置滚动新附加的recyclervViews?

注意:我也测试过scrollToPosition(),它没有遇到这样的问题.但我不能在我的情况下使用它.因为用户可以滚动到可能不是确切位置的任何x位置.所以我需要使用x值而不是位置来设置滚动位置.

编辑:您可以查看源代码

android scroll android-recyclerview

11
推荐指数
1
解决办法
1533
查看次数

禁用动作列表的滚动效果

我有一个GuidedStepSupportFragment这样的片段。

public class SampleStepFragment extends GuidedStepSupportFragment {

    @NonNull
    @Override
    public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
        String title = "Title";
        String breadcrumb = "Breadcrumb";
        String description = "Description";
        Drawable icon = getActivity().getDrawable(R.drawable.ic_videocam_black_24dp);

        return new GuidanceStylist.Guidance(title, description, breadcrumb, icon);
    }

    @Override
    public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {

        addAction(actions, ACTION_CONTINUE, "Action1");
        addAction(actions, ACTION_BACK, "Action2");

    }
}
Run Code Online (Sandbox Code Playgroud)

动作1

问题:当我滚动操作列表时,它显示如下;

动作1

但我想要这样的东西;

预期的

如何在我的操作列表中禁用此效果?

谢谢

android android-tv leanback

6
推荐指数
1
解决办法
1033
查看次数

EditText填充属性不适用于API 21和22

设置我EditText的填充值.但它不适用于2122 api版本.然而,它完全适用于19,23,24.

这是我的代码:

<style name="LoginEditTextStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_gravity">center_horizontal</item>
        <item name="android:maxLines">1</item>
        <item name="android:paddingLeft">@dimen/login_text_padding</item>
        <item name="android:paddingRight">@dimen/login_text_padding</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

这是我在布局xml中的edittext

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          android:layout_marginTop="@dimen/login_container_child_view_top_margin"
            android:alpha="0">

            <EditText
                android:id="@+id/login_username_editText"
                style="@style/LoginEditTextStyle"
                android:hint="@string/user_name"
                android:inputType="text"
                />

        </android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

21 api版本的结果

在此输入图像描述

适用于24 api版本

在此输入图像描述

我知道edittext/spinner视图有一个bug来设置xml的填充值.

我知道这个问题有一些解决方案,比如设置padmatic值programmaticaly.但它对我不起作用.

例如:这个被接受的解决方案对我不起作用

int paddingLeft = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
        int paddingRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 55, getResources().getDisplayMetrics());
        int paddingTop = editText.getPaddingTop();
        int paddingBottom = editText.getPaddingBottom();
        editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
Run Code Online (Sandbox Code Playgroud)

android padding android-version android-edittext

5
推荐指数
1
解决办法
390
查看次数

样式属性不适用于带有后缀或前缀的输入

设置样式属性正在使用。

 <Input
      style={{ borderWidth: this.state.focused ? "4px" : "1px" }}
      placeholder="this works"
      onMouseEnter={() => this.setState({ focused: true })}
      onMouseLeave={() => this.setState({ focused: false })}
    />
Run Code Online (Sandbox Code Playgroud)

但是,当我使用Input组件的 suffix 或 prefix 属性时,它不起作用。

    <Input
          style={{ borderWidth: this.state.focused ? "4px" : "1px" }}
          placeholder="not this"
          /*only difference is this suffix line*/
          suffix={<Icon type="save" />}
          onMouseEnter={() => this.setState({ focused: true })}
          onMouseLeave={() => this.setState({ focused: false })}
        />
Run Code Online (Sandbox Code Playgroud)

当我在浏览器上检查源代码时,它给了我原因。

1.案例:

<input placeholder="this works" type="text" class="ant-input" style="border-width: 1px;">
Run Code Online (Sandbox Code Playgroud)

2.情况:

<span class="ant-input-affix-wrapper" style="border-width: 1px;"><input placeholder="not …
Run Code Online (Sandbox Code Playgroud)

javascript input reactjs antd

5
推荐指数
1
解决办法
2850
查看次数

XmlPullParserException不支持的功能

我试图从我的android项目中的jar文件中读取一个可绘制的xml文件.

private Drawable readDrawableFromJar(String p_strFilePath) {
        InputStream stream = getClass().getClassLoader().getResourceAsStream(p_strFilePath);
        XmlPullParser parser = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            factory.setValidating(true);
            factory.setNamespaceAware(true);
            parser = factory.newPullParser();
            parser.setInput(stream, "UTF-8");
        } catch (XmlPullParserException e) {
            Log.e(LOG_TAG, "there is something for " + p_strFilePath + " " + e);
        }


        Drawable drawable = null;
        try {
            if (parser != null) {
                drawable = VectorDrawableCompat.createFromXml(getContext().getResources(), parser);

               return drawable ;
            } else {
                Log.e(LOG_TAG, "parser is null for " + p_strFilePath);
            }

        } catch (XmlPullParserException e) …
Run Code Online (Sandbox Code Playgroud)

java xml android drawable android-vectordrawable

3
推荐指数
1
解决办法
329
查看次数

以编程方式调整vectordrawable图标

我在我的android项目中动态显示一些VectorDrawable图标.但是,我无法使用以下代码在java层中缩放图标:

VectorDrawable jDrawable = (VectorDrawable) getContext().getDrawable(nResourceID);

// resize the icon
jDrawable.setBounds(30, 30, 30, 30);

// set the icon in the button view
button.setCompoundDrawablesRelativeWithIntrinsicBounds(jDrawable, null, null, null);
Run Code Online (Sandbox Code Playgroud)

注意:Android如何以编程方式调整(缩放)xml矢量图标的答案并不能解决我的问题.

java android android-vectordrawable

3
推荐指数
1
解决办法
2226
查看次数