Support
Quality
Security
License
Reuse
kandi has reviewed SuperTextView and discovered the below as its top functions. This is intended to give you an instant insight into SuperTextView implemented functionality, and help decide if they suit your requirements.
a super textview for android
3.1、Android Studio导入方法,添加Gradle依赖
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
3.2、项目中如何使用
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="80dp"
stv:sCenterBottomTextColor="@color/colorAccent"
stv:sCenterBottomTextString="限额说明>>"
stv:sCenterTopTextString=" "
stv:sCenterViewGravity="left_center"
stv:sLeftBottomTextString="招商银行(8888)"
stv:sLeftIconRes="@drawable/bank_zhao_shang"
stv:sLeftTopTextString="银行卡支付"
stv:sLeftViewGravity="left_center"
stv:sRightCheckBoxRes="@drawable/circular_check_bg"
stv:sRightViewType="checkbox" />
注意:
1、上下的线可以通过 sDividerLineType 设置 有四种显示方式 none,top,bottom,both
2、通过设置 sUseRipple=true 开启水波效果
License
Copyright 2016 Allen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
QUESTION
RecyclerView overdraws items
Asked 2017-Nov-01 at 11:36I'm facing a pretty odd issue with all the RecyclerView
in my application. It's not the first time that I use RecyclerView
but that's the first time it happens. I think the best way to explain this is with a photo:
The list is constantly updated so the notify methods are called often. The code is a bit too complicated to be posted but I'm sure that everything is called from the UI thread.
As requested here are the code and the layout.
Code:
public class PlayersAdapter extends RecyclerView.Adapter<PlayersAdapter.ViewHolder> {
private final List<GameInfo.Player> players;
private final LayoutInflater inflater;
public PlayersAdapter(Context context, List<GameInfo.Player> players) {
this.inflater = LayoutInflater.from(context);
this.players = players;
setHasStableIds(true);
}
@Override
public long getItemId(int position) {
return players.get(position).name.hashCode();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(parent);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
GameInfo.Player player = players.get(position);
holder.name.setText(player.name);
holder.update(player);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
if (payloads.isEmpty()) {
onBindViewHolder(holder, position);
} else {
holder.update((GameInfo.Player) payloads.get(0));
}
}
@Override
public int getItemCount() {
return players.size();
}
public void notifyItemChanged(GameInfo.Player player) {
int pos = players.indexOf(player);
if (pos != -1) {
players.set(pos, player);
notifyItemChanged(pos, player);
}
}
public void notifyDataSetChanged(List<GameInfo.Player> players) {
this.players.clear();
this.players.addAll(players);
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
final TextView name;
final SuperTextView score;
final ImageView status;
ViewHolder(ViewGroup parent) {
super(inflater.inflate(R.layout.player_item, parent, false));
setIsRecyclable(false);
name = itemView.findViewById(R.id.playerItem_name);
score = itemView.findViewById(R.id.playerItem_score);
status = itemView.findViewById(R.id.playerItem_status);
}
void update(GameInfo.Player player) {
score.setHtml(R.string.score, player.score);
switch (player.status) {
case HOST:
status.setImageResource(R.drawable.ic_person_black_48dp);
break;
case IDLE:
status.setImageResource(R.drawable.ic_access_time_black_48dp);
break;
case JUDGING:
case JUDGE:
status.setImageResource(R.drawable.ic_gavel_black_48dp);
break;
case PLAYING:
status.setImageResource(R.drawable.ic_hourglass_empty_black_48dp);
break;
case WINNER:
status.setImageResource(R.drawable.ic_star_black_48dp);
break;
case SPECTATOR:
status.setImageResource(R.drawable.ic_remove_red_eye_black_48dp);
break;
}
}
}
}
The GameInfo.Player
class:
public static class Player {
public final String name;
public final int score;
public final PlayerStatus status;
public Player(JSONObject obj) throws JSONException {
name = obj.getString("N");
score = obj.getInt("sc");
status = PlayerStatus.parse(obj.getString("st"));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Player player = (Player) o;
return name.equals(player.name);
}
}
Custom item layout (R.layout.player_item):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="4dp">
<ImageView
android:id="@+id/playerItem_status"
android:layout_width="32dp"
android:layout_height="32dp"
android:alpha="0.54"
android:padding="4dp"
android:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="8dp">
<TextView
android:id="@+id/playerItem_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="@android:color/primary_text_light"
android:textSize="14sp" />
<com.gianlu.commonutils.SuperTextView
android:id="@+id/playerItem_score"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
EDIT:
Removing the onBindViewHolder(ViewHolder holder, int position, List<Object> payloads)
method fixes the issue only if I use notifyItemChanged(pos, player)
, the issue remains with notifyItemChanged(pos)
. Would be nice to know why it happens.
ANSWER
Answered 2017-Nov-01 at 11:36I've fixed the issue by removing the onBindViewHolder(ViewHolder holder, int position, List<Object> payloads)
method, using notifyItemChanged(pos)
instead of notifyItemChanged(pos, player)
and setting the ViewHolder
recyclable with setIsRecyclable(true)
. Thanks to @RahulKumar for the suggestion.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit