2015-09-08 69 views
0

我目前有一個由Imageview組成的視圖列表。我試圖在列表的每個圖像視圖上添加文本。在Android上的ImageView中添加文本

這裏是視圖管理:一個叫做ImgView方法的調用,它的上下文和關聯視圖。

public ImgView(Context c, ImageView ImageV) { 
    mImageView = filteredImage; 
    mImageView.setTag(this); 

    mFiltersText = new TextView(c); 
    mFiltersText.setText("No effect"); 
    mFiltersText.setVisibility(View.VISIBLE); 

    mContext = c; 
    mImage = new GPUImage(mContext); 
    mEffect = R.id.none; 
    mActivity = (Activity) mContext; 
} 

的mEffect只是用了才知道效果我想申請在PIC的類型和存儲在XML一個int

<resources> 
    <item type="id" name="none" /> 
    <item type="id" name="blackandwhite" /> 
    <item type="id" name="bla" /> 
</resources> 

我的目標是要找到一種方式來獲得從字符串xml並在圖像視圖中顯示此字符串。

例如,選擇「無」身份證時,我顯示「沒有影響」的形象

我定義mFilterText上,但它不顯示任何內容。

的觀點是得到如下圖所示:

public View getView(int position, View convertView, ViewGroup parent) { 
    .... 
    convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_filter, null); 
    filteredImage = (ImageView) convertView.findViewById(R.id.filteredImage); 
    filteredImage.setBackground(new BitmapDrawable(mFakeBitmap)); 
    filteredText = new TextView(mContext); 

它可能是filteredText未正確使用。我用它作爲新的,但也許我需要將它附加到FilteredImage做。

任何想法

回答

0

只需將TextView放在ImageView的頂部。

+0

如何把頂部的繪製財產?我的佈局描述了一個列表視圖,並將其放入圖像視圖中 – Seb

+0

從xml中的項膨脹視圖,例如'LayoutInflater.from(context).inflate(layoutId,viewgroup,false);'其中layoutId是包含ViewGroup的佈局的id帶有TextView的ImageView。 – dtx12

+0

我需要在哪裏添加信息?我的ViewGroup從佈局的xml文件中的ListView描述中獲取參數 – Seb

0

使用的FrameLayout

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
    /> 

</FrameLayout> 

您還可以使用的TextView

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_clear_white_24dp" 
    android:drawableRight="@drawable/ic_clear_white_24dp" 
    android:drawableBottom="@drawable/ic_clear_white_24dp" 
    android:drawableTop="@drawable/ic_clear_white_24dp" 
/> 
+0

我的佈局定義爲FrameLayout,但ImageView沒有定義爲ImageView,xml定義了ListView。按照這種方法,文本出現在屏幕上。我的ListView包含一個可滾動的圖像列表。 imageview作爲方法的參數,並由調用者使用Layoutinflater。 – Seb

相關問題