我一直试图追踪这个问题一段时间了.我想我前段时间确实找到了解释.不幸的是,它丢失了代码注释.
我正在尝试Material Borderless-Button用Java 创建一个.首先,这是按钮在框架中的样子:
按钮bg(button_borderless_material.xml):
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item android:id="@id/mask"
android:drawable="@drawable/btn_default_mtrl_shape" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
在drawable被用作掩模(btn_default_mtrl_shape.xml):
<?xml version="1.0" encoding="utf-8"?>
<!-- Used as the canonical button shape. -->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/button_inset_horizontal_material"
android:insetTop="@dimen/button_inset_vertical_material"
android:insetRight="@dimen/button_inset_horizontal_material"
android:insetBottom="@dimen/button_inset_vertical_material">
<shape android:shape="rectangle"
android:tint="?attr/colorButtonNormal">
<corners android:radius="@dimen/control_corner_material" />
<solid android:color="@color/white" />
<padding android:left="@dimen/button_padding_horizontal_material"
android:top="@dimen/button_padding_vertical_material"
android:right="@dimen/button_padding_horizontal_material"
android:bottom="@dimen/button_padding_vertical_material" />
</shape>
</inset>
Run Code Online (Sandbox Code Playgroud)
Java等价于inset-drawable(btn_default_mtrl_shape.xml):
Drawable createButtonShape(Context context, int color) {
Resource res = context.getResources();
int radius = res
.getDimensionPixelSize(R.dimen.control_corner_material);
int …Run Code Online (Sandbox Code Playgroud) 问题标题可能是荒谬的.我正在创建一组自定义视图,这些视图将放置在单个父布局中 - 自定义FrameLayout.
这些自定义视图具有自己的样式attr,它们使用父级样式attr设置.
作为一个例子,考虑Parent是习惯FrameLayout.其风格attr定义attrs.xml如下:
<attr name="parentStyleAttr" format="reference" />
Run Code Online (Sandbox Code Playgroud)
该Child也有其ATTR:
<attr name="childStyleAttr" format="reference" />
Run Code Online (Sandbox Code Playgroud)
并将Parent其可定制的attr定义为:
<declare-styleable name="Parent">
<attr name="childStyleAttr" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
Child's 风格的attr:
<declare-styleable name="Child">
<attr name="childBgColor" format="color" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
在此之后,我为父母定义了一个样式:
<style name="ParentStyle">
<item name="childStyleAttr">@style/ChildStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
一个用于Child:
<style name="ChildStyle">
<item name="childBgColor">@color/blah</item>
</style>
Run Code Online (Sandbox Code Playgroud)
因为Parent,我parentStyleAttr在应用程序的主题中设置:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="parentStyleAttr">@style/ParentStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在,在Parent创建时,它会扩展包含Child以下内容的布局:
LayoutInflater.from(getContext()).inflate(R.layout.child, …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的问题.我有一个自定义ListView用BaseAdapter.在我的ListView行布局中,我有几个TextViews Buttons,和a SeekBar.一切都很好,没有任何问题,除了回收.
会发生什么:SeekBar除了可见之外,所有的都是隐藏的.的SeekBar是,当看到MediaPlayer上排播放.那部分也很有效.
但是,当用户向上或向下滚动,并且具有可见的行SeekBar不在视图中时,它会循环使用,并且SeekBar也会被回收,并且即使它不可见并且该行未播放(mp)也会不断更新.当用户向后滚动以返回正在播放的视图时,SeekBar是可见的,但是没有更新,它的位置是0.而是随机SeekBar更新,但它不可见(我测试的时候所有SeekBar的都可见所以我知道发生)
当然,我可以完成最愚蠢的解决方案并禁用ListView回收,但这会让用户体验非常糟糕,并且可能会使应用程序耗尽内存,并且使用LargeHeap是蹩脚的.所以以下方法是不可能的.
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
Run Code Online (Sandbox Code Playgroud)
我的问题:这有什么明显的解决方案吗?如何仅保留一行不被回收?我不会发布代码,直到它真的有必要,代码太大了.相反,我将发布与问题相关的重要部分:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
holder = null;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); …Run Code Online (Sandbox Code Playgroud) 这个UI元素非常重要.并且有充分的理由,因为它为开发人员和用户提供了标准的UI元素.所以,请理解我不想反驳它的用处.
动作栏模式:(取自此处)
It provides several key functions:
* Makes important actions prominent and accessible in a predictable way
(such as New or Search).
* Supports consistent navigation and view switching within apps.
* Reduces clutter by providing an action overflow for rarely used actions.
* Provides a dedicated space for giving your app an identity.
Run Code Online (Sandbox Code Playgroud)
如果您不熟悉编写Android应用程序,请注意操作栏是您可以实现的最重要的设计元素之一.遵循此处描述的指南将大大有助于使您的应用程序界面与核心Android应用程序保持一致.
问题:
Action Bar是必不可少的吗?如果选择放弃此模式(可能在导航部门中),是否存在无法实现的功能?是否存在任何平台或设备特定问题?