Android - 如何在CollapsingToolbarLayout中选择Marquee?

时间:2018-03-09 04:10:14

标签: android android-collapsingtoolbarlayout

我正在尝试在<AppBarLayout> <CollapsingToolbarLayout> <ImageView/> // Background <MarqueeToolbar/> </CollapsingToolbarLayout> </AppBarLayout> 标题中实现选框。

我的布局结构是:

MarqueeToolbar

public class MarqueeToolbar extends Toolbar { TextView title; public MarqueeToolbar(Context context) { super(context); } public MarqueeToolbar(Context context, AttributeSet attrs) { super(context, attrs); } public MarqueeToolbar(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public void setTitle(CharSequence title) { if (!reflected) { reflected = reflectTitle(); } super.setTitle(title); selectTitle(); } @Override public void setTitle(int resId) { if (!reflected) { reflected = reflectTitle(); } super.setTitle(resId); selectTitle(); } boolean reflected = false; private boolean reflectTitle() { try { Field field = Toolbar.class.getDeclaredField("mTitleTextView"); field.setAccessible(true); title = (TextView) field.get(this); title.setEllipsize(TextUtils.TruncateAt.MARQUEE); title.setMarqueeRepeatLimit(-1); title.setFocusable(true); title.setFocusableInTouchMode(true); title.canScrollHorizontally(1); title.setSingleLine(); return true; } catch (NoSuchFieldException e) { e.printStackTrace(); return false; } catch (IllegalAccessException e) { e.printStackTrace(); return false; } catch (NullPointerException e) { e.printStackTrace(); return false; } } public void selectTitle() { if (title != null) title.setSelected(true); } } 的位置:

MarqueeToolbar

尝试使用我从SO中某处复制的CollapsingToolbarLayout

然后我深入研究了CollapsingTextHelper,发现它在onLayout中使用Toolbar来绘制文本,而不是ToolbarToolbar用于获取标题,因此无论我做什么来更改@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); ... // Finally, set our minimum height to enable proper AppBarLayout collapsing if (mToolbar != null) { if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) { // If we do not currently have a title, try and grab it from the Toolbar mCollapsingTextHelper.setText(mToolbar.getTitle()); } if (mToolbarDirectChild == null || mToolbarDirectChild == this) { setMinimumHeight(getHeightWithMargins(mToolbar)); } else { setMinimumHeight(getHeightWithMargins(mToolbarDirectChild)); } } updateScrimVisibility(); 属性似乎都没用。

CollapsingToolbarLayout

}

我尝试延长onLayout,但我陷入困境,我要更改的部分位于CollapsingTextHelper,而android.support是受限制的CollapsingTextHelper类。

private void calculateUsingTextSize(final float textSize) { ... final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth, TextUtils.TruncateAt.END); if (!TextUtils.equals(title, mTextToDraw)) { mTextToDraw = title; mIsRtl = calculateIsRtl(mTextToDraw); } } 中绘制文字的部分似乎位于

CollapsingToolbarLayout

如何使用Dim path As String path = "\\server_name\all_users\documents\"

来实现选框

0 个答案:

没有答案