标签:
首先说一下我在网上找了很久没有找到说明方法所以我就自己试着写了一下
1、我自定义了一个继承了RelativeLayout的ViewGroup
java代码如下:
/** * 简单自定义三头像 * @author M.Z */ public class MyGroupHeaderImg extends RelativeLayout { public MyGroupHeaderImg(Context context, AttributeSet attrs) { super(context, attrs); this.mContext = context; mView = inflate(context, R.layout.view_group_head_img,this); initView(); } public MyGroupHeaderImg(Context context, AttributeSet attrs, int defStyle) { this(context, attrs); } private Context mContext; private CircleProgressBar firstImg,scendImg,threeImg; private View mView; /** * 初始化 */ private void initView() { firstImg = (CircleProgressBar) mView.findViewById(R.id.first_ivAvator); scendImg = (CircleProgressBar) mView.findViewById(R.id.scend_ivAvator); threeImg = (CircleProgressBar) mView.findViewById(R.id.three_ivAvator); } /** * 设置Url * @param avatorUrls */ public void setAvatorArray(String[] avatorUrls){ VocImageLoader.getInstance().displayImage(avatorUrls[0], firstImg, MyDisplayImageOptions.getAvatorImageOption(), null, null); VocImageLoader.getInstance().displayImage(avatorUrls[1], scendImg, MyDisplayImageOptions.getAvatorImageOption(), null, null); VocImageLoader.getInstance().displayImage(avatorUrls[2], threeImg, MyDisplayImageOptions.getAvatorImageOption(), null, null); } }
xml布局如下:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:circleBar="http://schemas.android.com/apk/res/com.iflytek.vocation_edu_cloud" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/transparent"> <com.iflytek.voc_edu_cloud.view.CircleProgressBar android:id="@+id/scend_ivAvator" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignRight="@+id/first_ivAvator" android:layout_alignTop="@+id/first_ivAvator" android:layout_marginRight="19dp" android:layout_marginTop="32dp" android:contentDescription="@string/app_name" circleBar:border_color="@color/white" circleBar:border_progress="100" circleBar:border_width="1dp" circleBar:inner_border_color="#ffffff" circleBar:one_src="@drawable/defult_avatar" /> <com.iflytek.voc_edu_cloud.view.CircleProgressBar android:id="@+id/three_ivAvator" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignLeft="@+id/first_ivAvator" android:layout_alignTop="@+id/scend_ivAvator" android:layout_marginLeft="21dp" android:contentDescription="@string/app_name" circleBar:border_color="@color/white" circleBar:border_progress="100" circleBar:border_width="1dp" circleBar:inner_border_color="#ffffff" circleBar:one_src="@drawable/defult_avatar" /> <com.iflytek.voc_edu_cloud.view.CircleProgressBar android:id="@+id/first_ivAvator" android:layout_width="50dp" android:layout_height="50dp" android:layout_centerHorizontal="true" android:contentDescription="@string/app_name" circleBar:border_color="@color/white" circleBar:border_progress="100" circleBar:border_width="1dp" circleBar:inner_border_color="#ffffff" circleBar:one_src="@drawable/defult_avatar" /> </RelativeLayout>
因为我布局自定义的ViewGroup中包含了一个自定义的View,而且有个xmlns:circleBar="http://schemas.android.com/apk/res/com.iflytek.vocation_edu_cloud"
导致我在调用的时候 是一片空白调用的xml如下:
<com.iflytek.voc_edu_cloud.view.MyGroupHeaderImg android:id="@+id/member_item_ivAvator" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentLeft="true" android:contentDescription="@string/app_name" />
解决方法:
要解决不显示的问题也很简单就是在调用的地方加上这句 xmlns:circleBar="http://schemas.android.com/apk/res/com.iflytek.vocation_edu_cloud"如下:
<com.iflytek.voc_edu_cloud.view.MyGroupHeaderImg xmlns:circleBar="http://schemas.android.com/apk/res/com.iflytek.vocation_edu_cloud" android:id="@+id/member_item_ivAvator" android:layout_width="80dp" android:layout_height="80dp" android:layout_alignParentLeft="true" android:contentDescription="@string/app_name" />
之后就可以正常的使用了.
自定义的ViewGroup中添加自定义View 造成的无法显示问题(个人)
标签:
原文地址:http://www.cnblogs.com/woaixingxing/p/5689377.html