下面列出了android.widget.FrameLayout#getChildAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layoutResId());
FrameLayout activityRoot = (FrameLayout) findViewById(android.R.id.content);
View parent = activityRoot.getChildAt(0);
// better way ?
mAnimated = new AnimatedDoorLayout(this);
activityRoot.removeView(parent);
activityRoot.addView(mAnimated, parent.getLayoutParams());
mAnimated.addView(parent);
mDoorType = getIntent().getIntExtra("door_type", AnimatedDoorLayout.HORIZONTAL_DOOR);
mAnimated.setDoorType(mDoorType);
ObjectAnimator animator = ObjectAnimator.ofFloat(mAnimated, ANIMATED_DOOR_LAYOUT_FLOAT_PROPERTY, 1).setDuration(600);
animator.start();
}
private AndroidBug5497Workaround(Activity activity) {
//获取状态栏的高度
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
this.activity = activity;
FrameLayout content = (FrameLayout)activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
//界面出现变动都会调用这个监听事件
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
if (isfirst) {
contentHeight = mChildOfContent.getHeight();//兼容华为等机型
isfirst = false;
}
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams)
mChildOfContent.getLayoutParams();
}
protected void adjustMarginAndPadding(){
FrameLayout contentLayout = (FrameLayout) findViewById(R.id.content_layout);
if(contentLayout != null){
if(Build.VERSION.SDK_INT >= 23) {
contentLayout.setPaddingRelative(0, contentLayout.getPaddingTop(), 0, Util.getNavigationBarHeight(this));
} else if(Build.VERSION.SDK_INT == 18){
contentLayout.setPaddingRelative(0, 0, 0, 0);
if(this instanceof SettingsActivity){
LinearLayout childView = (LinearLayout) contentLayout.getChildAt(0);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) childView.getLayoutParams();
params.topMargin = params.bottomMargin;
childView.setLayoutParams(params);
}
}
}
}
/**
* Fix the bug of 5497 in Android.
* <p>It will clean the adjustResize</p>
*
* @param window The window.
*/
public static void fixAndroidBug5497(@NonNull final Window window) {
int softInputMode = window.getAttributes().softInputMode;
window.setSoftInputMode(softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
final FrameLayout contentView = window.findViewById(android.R.id.content);
final View contentViewChild = contentView.getChildAt(0);
final int paddingBottom = contentViewChild.getPaddingBottom();
final int[] contentViewInvisibleHeightPre5497 = {getContentViewInvisibleHeight(window)};
contentView.getViewTreeObserver()
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = getContentViewInvisibleHeight(window);
if (contentViewInvisibleHeightPre5497[0] != height) {
contentViewChild.setPadding(
contentViewChild.getPaddingLeft(),
contentViewChild.getPaddingTop(),
contentViewChild.getPaddingRight(),
paddingBottom + getDecorViewInvisibleHeight(window)
);
contentViewInvisibleHeightPre5497[0] = height;
}
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layoutResId());
FrameLayout activityRoot = (FrameLayout) findViewById(android.R.id.content);
View parent = activityRoot.getChildAt(0);
// better way ?
mAnimated = new AnimatedRectLayout(this);
activityRoot.removeView(parent);
activityRoot.addView(mAnimated, parent.getLayoutParams());
mAnimated.addView(parent);
mAnimationType = getIntent().getIntExtra("animation_type", AnimatedRectLayout.ANIMATION_RANDOM);
mAnimated.setAnimationType(mAnimationType);
ObjectAnimator animator = ObjectAnimator.ofFloat(mAnimated, ANIMATED_RECT_LAYOUT_FLOAT_PROPERTY, 1).setDuration(600);
animator.start();
}
@Override
public final View getView(final int position, final View convertView,
final ViewGroup parent) {
//Log.d(TAG, "Creating a view based on " + convertView
// + " with position " + position);
final TreeNodeInfo<T> nodeInfo = getTreeNodeInfo(position);
if (convertView == null) {
//Log.d(TAG, "Creating the view a new");
final LinearLayout layout = (LinearLayout) layoutInflater.inflate(
getTreeListItemWrapperId(), null);
return populateTreeItem(layout, getNewChildView(nodeInfo),
nodeInfo, true);
} else {
//Log.d(TAG, "Reusing the view");
final LinearLayout linear = (LinearLayout) convertView;
final FrameLayout frameLayout = (FrameLayout) linear
.findViewById(R.id.treeview_list_item_frame);
final View childView = frameLayout.getChildAt(0);
updateView(childView, nodeInfo);
return populateTreeItem(linear, childView, nodeInfo, false);
}
}
protected void setUp() throws Exception {
super.setUp();
mInstr = this.getInstrumentation();
testActivity = this.getActivity();
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
innerContainer = (LinearLayout) containerView.getChildAt(0);
testView = (CordovaWebView) innerContainer.getChildAt(0);
touch = new TouchUtils();
touchTool = new Purity(testActivity, getInstrumentation());
}
private static int getContentViewInvisibleHeight(final Activity activity) {
final FrameLayout contentView = activity.findViewById(android.R.id.content);
final View contentViewChild = contentView.getChildAt(0);
final Rect outRect = new Rect();
contentViewChild.getWindowVisibleDisplayFrame(outRect);
Log.d("KeyboardUtils", "getContentViewInvisibleHeight: "
+ (contentViewChild.getBottom() - outRect.bottom));
return contentViewChild.getBottom() - outRect.bottom;
}
protected void setUp() throws Exception{
super.setUp();
testActivity = this.getActivity();
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
innerContainer = (LinearLayout) containerView.getChildAt(0);
testView = innerContainer.getChildAt(0);
}
protected void setUp() throws Exception{
super.setUp();
testActivity = this.getActivity();
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
innerContainer = (LinearLayout) containerView.getChildAt(0);
testView = innerContainer.getChildAt(0);
}
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
//incoming状态,localViewUserId为空
if (localViewUserId == null)
return;
if (localViewUserId.equals(userId)) {
localViewContainer.removeAllViews();
String currentUserId = RongIMClient.getInstance().getCurrentUserId();
FrameLayout remoteVideoView = (FrameLayout) remoteViewContainer.findViewWithTag(currentUserId);
localView = (SurfaceView) remoteVideoView.getChildAt(0);
remoteVideoView.removeAllViews();
localViewContainer.addView(localView);
TextView topUserNameView = (TextView) topContainer.findViewById(R.id.rc_voip_user_name);
UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(currentUserId);
if (userInfo != null) {
topUserNameView.setText(userInfo.getName());
} else {
topUserNameView.setText(currentUserId);
}
localViewUserId = currentUserId;
}
View singleRemoteView = remoteViewContainer.findViewWithTag(userId + "view");
if (singleRemoteView == null)
return;
LinearLayout container = (LinearLayout) singleRemoteView.getParent();
container.removeView(singleRemoteView);
if (container.equals(remoteViewContainer2)) {
if (remoteViewContainer1.getChildCount() > 0) {
View childView = remoteViewContainer1.getChildAt(0);
remoteViewContainer1.removeView(childView);
remoteViewContainer2.addView(childView);
}
}
}
protected void setUp() throws Exception {
super.setUp();
testActivity = this.getActivity();
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
innerContainer = (LinearLayout) containerView.getChildAt(0);
testView = (CordovaWebView) innerContainer.getChildAt(0);
}
public void removeBarValues() {
if (oldFrameLayout != null)
removeClickedBar();
final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();
for (int i = 0; i < barsCount; i++) {
FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);
int rootChildCount = rootFrame.getChildCount();
for (int j = 0; j < rootChildCount; j++) {
View childView = rootFrame.getChildAt(j);
if (childView instanceof LinearLayout) {
//bar
LinearLayout barContainerLinear = ((LinearLayout) childView);
int barContainerCount = barContainerLinear.getChildCount();
for (int k = 0; k < barContainerCount; k++) {
View view = barContainerLinear.getChildAt(k);
if (view instanceof Bar) {
BarAnimation anim = new BarAnimation(((Bar) view), (int) (mDataList.get(i).getBarValue() * 100), 0);
anim.setDuration(250);
((Bar) view).startAnimation(anim);
}
}
}
}
}
isBarsEmpty = true;
}
public static Bulletin find(@NonNull FrameLayout containerLayout) {
for (int i = 0, size = containerLayout.getChildCount(); i < size; i++) {
final View view = containerLayout.getChildAt(i);
if (view instanceof Layout) {
return ((Layout) view).bulletin;
}
}
return null;
}
private AndroidBug5497Workaround(Activity activity) {
this.activity = activity;
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
@ReactProp(name = "reset")
public void setReset(FrameLayout downloadButtonFrame, boolean reset) {
ArrowDownloadButton downloadButton = (ArrowDownloadButton) downloadButtonFrame.getChildAt(0);
if (reset) downloadButton.reset();
}
@ReactProp(name = "color")
public void setColor(FrameLayout shineButtonFrame, String color) {
ShineButton shineButton = (ShineButton) shineButtonFrame.getChildAt(0);
shineButton.setBtnColor(Color.parseColor(color));
}
public static void useWith(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
ViewGroup viewGroup = (ViewGroup) content.getChildAt(0);
swapMainLayoutWithDismissingLayout(viewGroup, activity);
}
@ReactProp(name = "backgroundColor")
public void setBackgroundColor(FrameLayout downloadButtonFrame, String backgroundColor) {
ArrowDownloadButton downloadButton = (ArrowDownloadButton) downloadButtonFrame.getChildAt(0);
downloadButton.setBackgroundColor(Color.parseColor(backgroundColor));
}
@ReactProp(name = "tintColor")
public void setTintColor(FrameLayout downloadButtonFrame, String tintColor) {
ArrowDownloadButton downloadButton = (ArrowDownloadButton) downloadButtonFrame.getChildAt(0);
// downloadButton.setBackgroundColor(Color.parseColor(tintColor));
}