gpt4 book ai didi

android - TextView setVisibility(View.GONE) 没有删除我的 CustomTextView

转载 作者:行者123 更新时间:2023-11-30 03:16:30 25 4
gpt4 key购买 nike

我正在使用自定义 TextView ,我试图在某些情况下隐藏它...但是当我使用方法 setVisibility(View.GONE) 时,我在某些设备 (Nexus 4) 上出现奇怪的行为, View 没有像它应该的那样隐藏,而是加载了来自另一个先前 TextView 的数据。

这是我的代码:

<ro.gebs.captoom.utils.fonts.CustomFontTextView
android:id="@+id/delete_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/layout_padding"
android:background="@drawable/rounded"
android:drawablePadding="10dp"
android:drawableRight="@drawable/input_delete_red"
android:padding="@dimen/layout_padding"
android:paddingLeft="10dp"
android:text="@string/delete"
android:textColor="@color/redish"
android:textSize="18sp"
custom:fontName="SemiBold"
android:visibility="gone"/>

CustomFontTextView 类:

package ro.gebs.captoom.utils.fonts;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

import ro.gebs.captoom.R;

public class CustomFontTextView extends TextView {

public CustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (!isInEditMode()) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFontTextView,
defStyle, 0);

assert a != null;
int fontId = a.getInteger(R.styleable.CustomFontTextView_fontName, -1);
if (fontId == -1) {
throw new IllegalArgumentException("The font_name attribute is required and must refer "
+ "to a valid child.");
}
a.recycle();
initialize(fontId);
}

}

public CustomFontTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public CustomFontTextView(Context context) {
super(context);
}

@SuppressWarnings("ConstantConditions")
public void initialize(int fontId) {

Typeface tf = null;
switch (fontId) {
case -1:
case 0:
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Regular.ttf");
break;
case 1:
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Bold.ttf");
break;
case 2:
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Semibold.ttf");
break;
case 3:
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-ExtraBold.ttf");
break;

}

setTypeface(tf);
}
}

我的 Activity 代码:

@Override
protected void onResume() {
super.onResume();

if (deleteBtnVisible) {
delete_btn.setVisibility(View.VISIBLE);
} else {
delete_btn.setVisibility(View.GONE);
}


Bundle extras = getIntent().getExtras();
if (extras != null) {
final int statusFolder = extras.getInt(Constants.STATUS, Constants.STATUS_NEW);
if (statusFolder == Constants.STATUS_EDIT) {
if (folder.getTitle().equals("Inbox")) {
delete_btn.setVisibility(View.GONE);
} else {
delete_btn.setVisibility(View.VISIBLE);
delete_btn.setEnabled(true);
}
}
}
}

有什么提示可以解决这个奇怪的问题吗?

最佳答案

试试这个:代替 View.GONE 使用 View.INVISIBLE

关于android - TextView setVisibility(View.GONE) 没有删除我的 CustomTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com