You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement ViewStub.inflate()
This commit is contained in:
@@ -1,16 +1,37 @@
|
|||||||
package android.view;
|
package android.view;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
public class ViewStub extends View {
|
public class ViewStub extends View {
|
||||||
|
|
||||||
|
private int layoutResource;
|
||||||
|
|
||||||
public ViewStub(Context context) {
|
public ViewStub(Context context) {
|
||||||
super(context);
|
this(context, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViewStub(Context context, AttributeSet attributeSet) {
|
public ViewStub(Context context, AttributeSet attributeSet) {
|
||||||
super(context, attributeSet);
|
this(context, attributeSet, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ViewStub(Context context, AttributeSet attributeSet, int defStyle) {
|
||||||
|
super(context, attributeSet, defStyle);
|
||||||
|
TypedArray a = context.obtainStyledAttributes(attributeSet, com.android.internal.R.styleable.ViewStub);
|
||||||
|
layoutResource = a.getResourceId(com.android.internal.R.styleable.ViewStub_layout, -1);
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public View inflate() {
|
||||||
|
if (layoutResource == -1)
|
||||||
|
throw new IllegalStateException("ViewStub must have a valid layoutResource");
|
||||||
|
ViewGroup parent = (ViewGroup) getParent();
|
||||||
|
View view = LayoutInflater.from(getContext()).inflate(layoutResource, parent, false);
|
||||||
|
int index = parent.indexOfChild(this);
|
||||||
|
parent.removeView(this);
|
||||||
|
parent.addView(view, index, getLayoutParams());
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user