2013-11-15 104 views
1

我正在使用自定义textview,我试图在某些情况下隐藏它...但是,当我在某些设备(Nexus 4)上时出现奇怪的行为使用方法setVisibility(View.GONE),视图不会被隐藏,因为它应该是加载了来自另一个以前的textview的数据。TextView setVisibility(View.GONE)不会删除我的CustomTextView

这里是我的代码:

<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); 
    } 
} 

我的活动代码:

@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); 
       } 
      } 
     } 
    } 

,可以解决这个奇怪的问题任何提示?

+0

“deleteBtnVisible” 什么是什么? – amalBit

+0

它是一个布尔值,告诉我是否需要显示我的文本视图 –

+0

View.GONE应该确保您的TextView不可见,并且在布局中不占用空间 – vamsiampolu

回答

1

试试这个:在地方View.GONE的使用View.INVISIBLE

+0

这不是我需要的功能,因为textview被放置在一个滚动,它在底部,所以我不想能够滚动一些白色的表面...查看。就我所知,INVISIBLE不会从ViewGroup中删除视图... –

相关问题