自定义控件getChildCount()得到总是1
以下是自定义组合控件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" >
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:alpha="0.5"
android:background="@android:color/background_dark"
android:ellipsize="marquee"
android:gravity="center"
android:focusable="true"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:paddingBottom="30px"
android:scrollHorizontally="false"
android:text="云端美食"
android:textSize="40px"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
在实现类中:
public class ImageTextView extends RelativeLayout
{
public ImageTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater flater = LayoutInflater.from(context);
flater.inflate(R.layout.custom_imagetext, this);
int count=getChildCount();
}
}
int count=getChildCount()为什么得到的总是1,而我的控件中有两个元素。请高人指点。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" >
</ImageView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:alpha="0.5"
android:background="@android:color/background_dark"
android:ellipsize="marquee"
android:gravity="center"
android:focusable="true"
android:lines="1"
android:marqueeRepeatLimit="marquee_forever"
android:paddingBottom="30px"
android:scrollHorizontally="false"
android:text="云端美食"
android:textSize="40px"
android:textStyle="bold" >
</TextView>
</RelativeLayout>
在实现类中:
public class ImageTextView extends RelativeLayout
{
public ImageTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater flater = LayoutInflater.from(context);
flater.inflate(R.layout.custom_imagetext, this);
int count=getChildCount();
}
}
int count=getChildCount()为什么得到的总是1,而我的控件中有两个元素。请高人指点。
...全文
相关推荐
android自定义控件自动换行效果实现
http://blog.csdn.net/amazing_alex/article/details/44872921
Android自定义控件ViewGroup实现标签云
主要为大家详细介绍了Android自定义控件ViewGroup实现标签云,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
ScrollView中自定义ListView
解决系统ListView不能直接放在ScrollView中,自定义了一个ListView,实现ListView全部功能
自定义流式布局
自定义流式布局,可以往里添加button,textview等控件
Android 自定义控件 EditText输入框两边加减按钮Button Demo
自己封装的一个EditText两边放加减按钮Button来控制输入框的数值


