我创建了发光效果 imageview 应用程序。它工作正常,我的问题是发光效果左,右,下,顶部有点隐藏,所以我正在尝试设置填充,但我仍然有同样的问题。如何解决这个问题呢?
代码:
ImageView mImageBk = (ImageView)itemTemplate.findViewById(R.id.imgBk);
RelativeLayout.LayoutParams ImgBKLayoutParams = new RelativeLayout.LayoutParams(scrWidth/8 + scrWidth/20, scrWidth/8 + scrWidth/20 );
ImgBKLayoutParams.leftMargin =0;
ImgBKLayoutParams.topMargin = 0;
mImageBk.setLayoutParams(ImgBKLayoutParams);
mImageBk.setImageResource(R.drawable.glow_effect);
mImageBk.setPadding(10, 10, 10, 10);
mImageBk.setVisibility(View.GONE);
完整代码:
public class tttAdapter extends BaseAdapter{
private Context mContext;
private int scrWidth=0;
private int scrHeight=0;
private int scrDpi = 0;
private boolean setInvisible = false;
private boolean visibleConf[];
private boolean selected[];
private boolean innerListView = false;
private int[] IMAGE_IDS = {
R.drawable.s_record, R.drawable.s_record
};
private String[] title = {
"Tv", "My Favorites List1"
};
private String[] detail = {
"Tv", "My Favorites List1"
};
public favoritesAdapter(Context context) {
mContext = context;
visibleConf = new boolean[IMAGE_IDS.length];
selected = new boolean[IMAGE_IDS.length];
}
public void updateImageSize(int width, int height, int dpi) {
scrWidth= width;
scrHeight = height;
scrDpi = dpi;
}
public void setTextVisible(int position){
if(IMAGE_IDS.length <= position)
return;
for(int i=0; i < IMAGE_IDS.length; i++) {
visibleConf[i] = false;
}
visibleConf[position] = true;
}
public int getCount() {
return IMAGE_IDS.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public void setTextInvisible(int position) {
visibleConf[position] = false;
}
public void setInnerViewVisible(boolean enable) {
innerListView = enable;
}
public void unsetSelectedItem(int position) {
for(int i=0; i < IMAGE_IDS.length; i++) {
selected[i] = false;
}
}
public void setSelectedItem(int position) {
for(int i=0; i < IMAGE_IDS.length; i++) {
selected[i] = false;
}
selected[position] = true;
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View itemTemplate = inflater.inflate(R.layout.list_item, null);
ImageView mImageBk = (ImageView)itemTemplate.findViewById(R.id.imgBk);
RelativeLayout.LayoutParams ImgBKLayoutParams = new RelativeLayout.LayoutParams(scrWidth/8 + scrWidth/20, scrWidth/8 + scrWidth/20 );
ImgBKLayoutParams.leftMargin =0;
ImgBKLayoutParams.topMargin = 0;
mImageBk.setLayoutParams(ImgBKLayoutParams);
mImageBk.setImageResource(R.drawable.glow_effect);
mImageBk.setPadding(10, 10, 10, 10);
mImageBk.setVisibility(View.GONE);
ImageView mImage = (ImageView)itemTemplate.findViewById(R.id.img);
RelativeLayout.LayoutParams ImgLayoutParams = new RelativeLayout.LayoutParams(scrWidth/8 , scrWidth/8 );
ImgLayoutParams.leftMargin = scrWidth/38;
ImgLayoutParams.topMargin = scrWidth/38;
mImage.setLayoutParams(ImgLayoutParams);
mImage.setImageResource(IMAGE_IDS[position]);
mImage.bringToFront();
TextView mTextTitle = (TextView)itemTemplate.findViewById(R.id.title);
mTextTitle.setClickable(false);
mTextTitle.setEnabled(true);
mTextTitle.setText(title[position]);
TextView mTextDetail = (TextView)itemTemplate.findViewById(R.id.detail);
mTextDetail.setClickable(false);
mTextDetail.setEnabled(true);
mTextDetail.setText(detail[position]);
if(selected[position] == true) {
ImageView mArrowImg = (ImageView)itemTemplate.findViewById(R.id.imgArrow);
//mArrowImg.setLayoutParams(new RelativeLayout.LayoutParams(scrWidth/32, scrHeight/32));
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(scrWidth/32, scrHeight/32);
layoutParams.leftMargin = scrWidth / 8;
layoutParams.topMargin = scrWidth / 16;
mArrowImg.setLayoutParams(layoutParams);
mArrowImg.setImageResource(R.drawable.arrow);
mImage.setBackgroundResource(R.drawable.test_glowb);
mTextTitle.setVisibility(View.GONE);
mTextDetail.setVisibility(View.GONE);
mImageBk.setVisibility(View.VISIBLE);
} else {
if(innerListView == true) {
mImage.setVisibility(View.GONE);
}
}
if(visibleConf[position] == true) {
mTextTitle.setTextSize((scrWidth*160) / (30 * scrDpi));
mTextDetail.setTextSize((scrWidth*160) / (50 * scrDpi));
mTextTitle.setTypeface(null,Typeface.BOLD);
mTextDetail.setTypeface(null,Typeface.BOLD);
mImageBk.setVisibility(View.VISIBLE);
} else {
mTextTitle.setTextSize((scrWidth*160) / (40 * scrDpi));
mTextDetail.setTextSize((scrWidth*160) / (70 * scrDpi));
//mTextTitle.setVisibility(View.GONE);
//mTextDetail.setVisibility(View.GONE);
mImage.setAlpha(150);
}
if(innerListView == true) {
mTextTitle.setVisibility(View.GONE);
mTextDetail.setVisibility(View.GONE);
}
return itemTemplate;
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/thumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/imgBk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="14dip"
android:layout_marginTop="30dp"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/thumb"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumb"
android:layout_toRightOf="@+id/thumb"
android:layout_centerVertical="true"
android:textColor="#ffffff" />
<TextView
android:id="@+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/thumb"
android:layout_alignParentBottom="true"
android:textColor="#ffffff" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgArrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</LinearLayout>
</RelativeLayout>