下面列出了android.view.View#setVisibility ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Dismisses the previously displayed alert message.
*/
private void hideAlertBar() {
View alertBar = findViewById(R.id.alert_bar);
if (alertBar != null && alertBar.getVisibility() != View.GONE) {
alertBar.setVisibility(View.GONE);
}
}
void updateObscuredViewVisibility() {
if (getChildCount() == 0) {
return;
}
final int leftBound = getPaddingLeft();
final int rightBound = getWidth() - getPaddingRight();
final int topBound = getPaddingTop();
final int bottomBound = getHeight() - getPaddingBottom();
final int left;
final int right;
final int top;
final int bottom;
if (mSlideableView != null && hasOpaqueBackground(mSlideableView)) {
left = mSlideableView.getLeft();
right = mSlideableView.getRight();
top = mSlideableView.getTop();
bottom = mSlideableView.getBottom();
} else {
left = right = top = bottom = 0;
}
View child = getChildAt(0);
final int clampedChildLeft = Math.max(leftBound, child.getLeft());
final int clampedChildTop = Math.max(topBound, child.getTop());
final int clampedChildRight = Math.min(rightBound, child.getRight());
final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
final int vis;
if (clampedChildLeft >= left && clampedChildTop >= top &&
clampedChildRight <= right && clampedChildBottom <= bottom) {
vis = INVISIBLE;
} else {
vis = VISIBLE;
}
child.setVisibility(vis);
}
/**
* 设置控件是否可见
* @param viewId
* @param visible
* @return
*/
public ViewHolder setVisible(int viewId, boolean visible)
{
View view = getView(viewId);
view.setVisibility(visible ? View.VISIBLE : View.GONE);
return this;
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
ListItemModel item = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.lng_zone_device_item, parent, false);
}
View itemView = convertView.findViewById(R.id.normal_item_container);
View headingView = convertView.findViewById(R.id.heading_item_continer);
if (item.isHeadingRow()) {
itemView.setVisibility(View.GONE);
headingView.setVisibility(View.VISIBLE);
return getViewForHeading(item, convertView);
}
else {
itemView.setVisibility(View.VISIBLE);
headingView.setVisibility(View.GONE);
boolean nextRowIsHeader = false;
boolean isLastRow = false;
try {
nextRowIsHeader = getItem(position + 1).isHeadingRow();
}
catch (Exception ignored) {
isLastRow = true;
}
return getViewForNonHeader(item, convertView, nextRowIsHeader, isLastRow);
}
}
private void toggleView(View view,Object obj){
if (obj==null){
view.setVisibility(View.GONE);
}else {
view.setVisibility(View.VISIBLE);
}
}
void setAllChildrenVisible()
{
int i = getChildCount();
for (int j = 0; j < i; j++)
{
View view = getChildAt(j);
if (view.getVisibility() == 4)
{
view.setVisibility(0);
}
}
}
void setAllChildrenVisible() {
for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == INVISIBLE) {
child.setVisibility(VISIBLE);
}
}
}
private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
mStatusBarTintView = new View(context);
LinearLayout.LayoutParams params = generateLayoutParams(LinearLayout.LayoutParams.MATCH_PARENT
, mConfig.getStatusBarHeight(),0);
if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
params.rightMargin = mConfig.getNavigationBarWidth();
}
mStatusBarTintView.setLayoutParams(params);
mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
mStatusBarTintView.setVisibility(View.GONE);
decorViewGroup.addView(mStatusBarTintView);
}
@Override
public final View generateView(
@NonNull final AppCompatActivity activity,
@Nullable final Integer textColor,
@Nullable final Float textSize,
final boolean showLinkButtons) {
if(mIsLinkButton && !showLinkButtons) {
// Don't show
final View result = new View(activity);
result.setVisibility(View.GONE);
return result;
}
final LinkDetailsView ldv = new LinkDetailsView(
activity,
mText,
mSubtitle);
final int linkMarginPx = General.dpToPixels(activity, 8);
final ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, linkMarginPx, 0, linkMarginPx);
ldv.setLayoutParams(layoutParams);
ldv.setOnClickListener(
generateOnClickListener(activity, textColor, textSize, showLinkButtons));
final View.OnLongClickListener longClickListener
= generateOnLongClickListener(activity, textColor, textSize, showLinkButtons);
if(longClickListener != null) {
ldv.setOnLongClickListener(longClickListener);
}
return ldv;
}
public void showContent(Object tag) {
View view = contents.get(tag);
if (view != null) {
view.setVisibility(View.VISIBLE);
//mainContent.setVisibility(View.GONE);
}
}
private void hideBottom(final View view, Animator.AnimatorListener listener) {
view.setVisibility(View.VISIBLE);
Animator iconAnim = ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f, view.getHeight()),
PropertyValuesHolder.ofFloat(View.ALPHA, 1f, 0f));
iconAnim.setDuration(VIEW_ANIMATION);
iconAnim.addListener(listener);
iconAnim.start();
}
public static void scaleShow(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
view.setVisibility(View.VISIBLE);
ViewCompat.animate(view)
.scaleX(1.0f)
.scaleY(1.0f)
.alpha(1.0f)
.setDuration(800)
.setListener(viewPropertyAnimatorListener)
.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
.start();
}
@BindingAdapter(value = {"showIfTrueInRecycler"}, requireAll = true)
public static void setShowIfTrueInRecycler(@NonNull View view, boolean isVisible) {
view.setVisibility(isVisible ? View.VISIBLE : View.GONE);
view.getLayoutParams().height = isVisible ? LinearLayout.LayoutParams.WRAP_CONTENT : 0;
}
public static void a(View view, int i) {
if (view != null)
view.setVisibility(i);
}
/**
* Sets editTextView visible and project button invisible.
*
* @param v Edit text view.
*/
private void showEditTextView(View v) {
Button bt = (Button) v.getTag(R.id.editbutton);
bt.setVisibility(View.INVISIBLE);
v.setVisibility(View.VISIBLE);
}
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
File file = getItem(position);
//noinspection ConstantConditions
((TextView) view.findViewById(android.R.id.text1)).setText(file.getName());
((TextView) view.findViewById(android.R.id.text2)).setText(
file.isDirectory() ? getDirectorySummary(file) : getFileSummary(file)
);
((TextView) view.findViewById(R.id.last_modified)).setText(
DateUtils.getRelativeDateTimeString(
mContext,
file.lastModified(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.WEEK_IN_MILLIS,
0
)
);
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
imageView.setColorFilter(mColor);
Picasso.with(mContext)
.load(file)
.resizeDimen(R.dimen.explorer_icon_size, R.dimen.explorer_icon_size)
.centerCrop()
.placeholder(ContextCompat.getDrawable(
mContext, file.isDirectory() ? R.drawable.ic_folder : R.drawable.ic_file
))
.into(imageView, new Callback() {
@Override
public void onSuccess() {
// Remove the tint once the image loads
imageView.setColorFilter(Color.argb(0, 0, 0, 0), PorterDuff.Mode.DST);
}
@Override
public void onError() {
}
});
View spacer = view.findViewById(R.id.spacer);
CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
if (mCheckboxes) {
checkBox.setOnCheckedChangeListener(null);
checkBox.setChecked(mChecked.indexOfKey(position) >= 0);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mChecked.put(position, getItem(position));
} else {
mChecked.remove(position);
if (mChecked.size() == 0) {
mListener.onAllItemsDeselected();
}
}
}
});
spacer.setVisibility(View.VISIBLE);
checkBox.setVisibility(View.VISIBLE);
} else {
spacer.setVisibility(View.GONE);
checkBox.setVisibility(View.GONE);
}
return view;
}
private void onDrop() {
destroyDragImageView();
removeCallbacks(mDelayedOnDragRunnable);
View v = getChildAt(mDropPosition);
v.setVisibility(View.VISIBLE);
v.clearAnimation();
if (mDragAndDropListener != null && mDropPosition != AdapterView.INVALID_POSITION) {
mDragAndDropListener.onDropItem(mDragPosition, mDropPosition);
}
mDragPosition = mDropPosition = mCurrentPosition = AdapterView.INVALID_POSITION;
mDragAndDropStarted = false;
}
/**
* 批量设置View visibility
*/
public static void setViewVisibility(int visibility, View... views) {
for (View v : views) {
v.setVisibility(visibility);
}
}
private void setCommentTextClick(TextView mTextView2, JSONArray data,
View view, int goodSize) {
if (goodSize > 0 && data.size() > 0) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
if (data.size() == 0) {
mTextView2.setVisibility(View.GONE);
} else {
mTextView2.setVisibility(View.VISIBLE);
}
SpannableStringBuilder ssb = new SpannableStringBuilder();
int start = 0;
for (int i = 0; i < data.size(); i++) {
JSONObject json = data.getJSONObject(i);
String content = json.getString("content");
String scID = json.getString("scID");
String userID_temp = json.getString("userID");
String nick = userID_temp;
if (userID_temp.equals(myuserID)) {
nick = myNick;
} else {
User user = MYApplication.getInstance().getContactList()
.get(userID_temp);
if (user != null) {
nick = user.getNick();
}
}
String content_0 = "";
String content_1 = ": " + content;
String content_2 = ": " + content + "\n";
if (i == (data.size() - 1) || (data.size() == 1 && i == 0)) {
ssb.append(nick + content_1);
content_0 = content_1;
} else {
ssb.append(nick + content_2);
content_0 = content_2;
}
ssb.setSpan(new TextViewURLSpan(nick, userID_temp, 1), start, start
+ nick.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (userID_temp.equals(myuserID)) {
ssb.setSpan(new TextViewURLSpan(nick, userID_temp, i, scID, 2,
mTextView2, data, view, goodSize), start,
start + nick.length() + content_0.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
start = ssb.length();
}
mTextView2.setText(ssb);
mTextView2.setMovementMethod(LinkMovementMethod.getInstance());
}
private void showContent(View contentView, View loadingView,
View emptyView) {
contentView.setVisibility(View.VISIBLE);
loadingView.setVisibility(View.GONE);
emptyView.setVisibility(View.GONE);
}