XML 레이아웃을 사용자 정의 ViewGroup
으로 확장하려고합니다. 레이아웃을 확장 한 후 ViewGroup
은 전체 레이아웃 파일을 ViewGroup
에 표시해야하는 레이아웃의 루트보기 만 표시합니다.XML 레이아웃을 사용자 정의 ViewGroup으로 확대
나는 stackoverflow 및 다른 웹 사이트에서 이와 관련하여 게시 된 다른 비슷한 질문을했지만 아무도 도움이되었습니다. 여기
내 사용자 정의ViewGroup
의 코드입니다 : 레이아웃 파일
ViewEvent event = new ViewEvent(getApplicationContext());
LayoutInflater inflator;
inflator=(LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflator.inflate(R.layout.try1, event);
setContentView(event);
다음입니다 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffaa77">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffff0000"
android:text="asdasadfas" />
</LinearLayout>
을
Activity
에서
public class ViewEvent extends ViewGroup {
private final String LOG_TAG="Month View Event";
public ViewEvent(Context context) {
super(context);
}
public ViewEvent(Context context,AttributeSet attrs) {
super(context,attrs);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int childCount= getChildCount();
for(int i=0;i<childCount;i++)
{
Log.i(LOG_TAG, "Child: " + i + ", Layout [l,r,t,b]: " + l + "," + r + "," + t + "," + b);
View v=getChildAt(i);
if(v instanceof LinearLayout)
{
Log.i(LOG_TAG, "Event child count: " + ((ViewGroup)v).getChildCount()); // displaying the child count 1
v.layout(0, 0, r-l, b-t);
}
//v.layout(l, r, t, b);
}
}
,이 사용자 지정보기 그룹을 사용하고 있습니다
이 레이아웃을 부 풀린 후에는 루트 만 가져옵니다. LinearLayout
은 배경색이 #ffff0000
입니다. TextView
이 표시되지 않습니다.
내가 잘못하거나 잘못하고있는 부분은 어디입니까?
그것은 액세스 할 수 있지만,이 표시되지 않습니다! –