프로그래밍 방식으로 TextView 및 EditView를 내 사용자 정의 LinearLayout에 추가하고 싶습니다. 하지만 어떻게해야할지 모르겠다. 이 같은 뭔가 (작동하지 않는) :사용자 정의 LinearLayout에서 standart보기를 사용할 수 있습니까
<com.custom.FavoritesViewer
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
android:id="@+id/favoritesViewer">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</com.custom.FavoritesViewer>
내 사용자 정의 레이아웃
public class FavoritesViewer extends LinearLayout {
private Bitmap fullImage;
private int canvasWidth;
private int canvasHeight;
private final Paint paint = new Paint();
public FavoritesViewer(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
initializeCanvasSize(context);
}
private void initializeCanvasSize(Context context) {
final Pair<Integer, Integer> screenSize = Utils.getScreenSize(context);
canvasWidth = screenSize.first;
canvasHeight = screenSize.second;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(canvasWidth, canvasHeight/3);
}
@Override
protected void onDraw(Canvas cvs) {
if (fullImage == null) {
fullImage = Bitmap.createBitmap(canvasWidth, canvasHeight/3, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(fullImage);
paint.reset();
paint.setColor(Color.parseColor("#AA000000"));
canvas.drawRect(0, 0, canvasWidth, canvasHeight/3, paint);
}
cvs.drawBitmap(fullImage, 0, 0, null);
}
}
그래서 내가 캔버스가 (배경 등) 내가 정상에 약간의 standart보기를 추가하고 싶습니다 . onDraw에 추가 할 수 없습니다.
보기를 사용자 정의 레이아웃에 추가하는 방법이 있습니까?
편집 해
나는 버튼을 몇 가지 특별한 UI를 구현해야합니다. 이 구성 요소를 하나의 구성 요소로 묶고 싶습니다. 캔버스에 그 UI를 그리고 어떻게 든 단추를 추가해야합니다 (이미지를 그리거나 단추의 동작을 에뮬레이션하지 않고 간단한 ImageButton을 추가하는 것으로 충분합니다). 그래서 레이아웃을 컨테이너로 선택하고 뷰를 프로그래밍 방식으로 추가해야합니다.
예 가능합니다. –
addView() 메소드가 있다는 것을 알고 있습니까? 어쩌면 일부 문서를 읽을 수 있습니다 ... http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams) – ElDuderino