RelativeLayout을 모든 생성자로 확장했습니다. 그리고 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" >
<EditText
android:id="@+id/clearable_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/clearable_button_clear"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:background="@drawable/image_clear"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"/>
</RelativeLayout>
을 팽창 그리고 이것은 잘 작동이
<com.and.MyClass
android:id="@+id/my_class"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
처럼 내 활동의 레이아웃에 MyClass에를 사용 MyClass에
public class MyClass extends RelativeLayout
{
LayoutInflater inflater = null;
EditText edit_text;
Button btn_clear;
public MyClass(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyClass(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_class_layout, this, true);
edit_text = (EditText) findViewById(R.id.clearable_edit);
btn_clear = (Button) findViewById(R.id.clearable_button_clear);
btn_clear.setVisibility(RelativeLayout.INVISIBLE);
}
public MyClass(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
}
내 클래스 레이아웃
내 코드입니다. 하지만 MyClass (Context context) 생성자에서 클래스 레이아웃을 확장하면 작동하지 않습니다.
문제가 발생하지 않습니다. 네가 내 질문을하기를 바란다.
당신이 내 의심을 해결해 주셔서 감사합니다. – AB1209