下面列出了怎么用android.widget.FrameLayout的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public View getView(Context context, final HintCase hintCase, ViewGroup parent) {
FrameLayout.LayoutParams frameLayoutParamsBlock = getParentLayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
gravity, marginLeft, marginTop, marginRight, marginBottom);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(frameLayoutParamsBlock);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setOrientation(LinearLayout.VERTICAL);
if (contentTitle != null) {
linearLayout.addView(getTextViewTitle(context));
}
if (existImage()) {
linearLayout.addView(getImage(context, imageView, imageResourceId));
}
if (contentText != null) {
linearLayout.addView(getTextViewDescription(context));
}
return linearLayout;
}
/**
* Constructor, adding a listener to change the global layout if required.
*
* @param activity the activity which uses the workaround.
*/
private AutoKeyboardLayoutUtility(@NonNull final Activity activity) {
FrameLayout content = activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
mFrameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
if (activity instanceof ActivityWithExplicitLayoutTrigger) {
mActivityWithLayoutTrigger = (ActivityWithExplicitLayoutTrigger) activity;
}
}
private void init(Context context){
actionButton=new FloatingActionButton(context);
toolbarLayout=new LinearLayout(getContext());
float density = getResources().getDisplayMetrics().density;
addView(actionButton,(int)(56*density),(int)(56*density));
FrameLayout.LayoutParams params=
FrameLayout.LayoutParams.class.cast(actionButton.getLayoutParams());
params.gravity= Gravity.CENTER;
actionButton.setLayoutParams(params);
toolbarLayout.setGravity(Gravity.CENTER);
actionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onButtonClick();
}
});
fabDrawable=actionButton.getDrawable();
if(fabDrawable!=null) actionButton.setImageDrawable(fabDrawable);
setToolbarColor(-1);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
FrameLayout.LayoutParams imgParams = (FrameLayout.LayoutParams) mCapturePhoto.getLayoutParams();
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 横屏
mScreenOrientation = Configuration.ORIENTATION_LANDSCAPE;
imgParams.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
} else {
// 竖屏
mScreenOrientation = Configuration.ORIENTATION_PORTRAIT;
imgParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
}
mCapturePhoto.setLayoutParams(imgParams);
if (mCamera != null)
startPreview(mCamera, mSvHolder);
super.onConfigurationChanged(newConfig);
}
@Override
protected MeasureOutput measure(int width, int height) {
MeasureOutput measureOutput = new MeasureOutput();
if (this.mOrientation == Constants.Orientation.HORIZONTAL) {
int screenW = WXViewUtils.getScreenWidth(WXEnvironment.sApplication);
int weexW = WXViewUtils.getWeexWidth(getInstanceId());
measureOutput.width = width > (weexW >= screenW ? screenW : weexW) ? FrameLayout.LayoutParams.MATCH_PARENT
: width;
measureOutput.height = height;
} else {
int screenH = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
int weexH = WXViewUtils.getWeexHeight(getInstanceId());
measureOutput.height = height > (weexH >= screenH ? screenH : weexH) ? FrameLayout.LayoutParams.MATCH_PARENT
: height;
measureOutput.width = width;
}
return measureOutput;
}
public FastShareVH(View itemView) {
super(itemView);
itemView.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
v = (SimpleDraweeView) itemView.findViewById(R.id.image);
chb = (CheckBox) itemView.findViewById(R.id.check);
int size = Screen.dp(80);
v.setLayoutParams(new FrameLayout.LayoutParams(size, size));
chb.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked && data != null) {
selected.add(data);
notifyVm();
} else {
selected.remove(data);
notifyVm();
}
});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabs = (TabWidget)findViewById(android.R.id.tabs);
ViewStub vStub = (ViewStub) findViewById(R.id.new_home_menu);
mMenuContainer = (FrameLayout) vStub.inflate();
mViewPager = (ViewPager)findViewById(R.id.pager);
mLoadingView = makeEmptyLoadingView(this, (RelativeLayout)findViewById(R.id.tabs_content));
setScrollerTime(800);
albumItem = (DisplayItem) getIntent().getSerializableExtra("item");
setUserFragmentClass();
getSupportLoaderManager().initLoader(TabsGsonLoader.LOADER_ID, null, this);
if (savedInstanceState != null) {
mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
}
}
/**
* Constructor that takes parameters collected using {@link FloatingActionMenu.Builder}
* @param activity a reference to the activity that will
* @param layoutParams
* @param theme
* @param backgroundDrawable
* @param position
* @param contentView
* @param contentParams
*/
public FloatingActionButton(Activity activity, LayoutParams layoutParams, int theme, Drawable backgroundDrawable, int position, View contentView, FrameLayout.LayoutParams contentParams) {
super(activity);
setPosition(position, layoutParams);
// If no custom backgroundDrawable is specified, use the background drawable of the theme.
if(backgroundDrawable == null) {
if(theme == THEME_LIGHT)
backgroundDrawable = activity.getResources().getDrawable(R.drawable.button_action_selector);
else
backgroundDrawable = activity.getResources().getDrawable(R.drawable.button_action_dark_selector);
}
setBackgroundResource(backgroundDrawable);
if(contentView != null) {
setContentView(contentView, contentParams);
}
setClickable(true);
attach(layoutParams);
}
public void testViewHolderItemBinding() {
final TestModel model1 = database.fetch(TestModel.class, 1, TestModel.PROPERTIES);
final TestModel model2 = database.fetch(TestModel.class, 2, TestModel.PROPERTIES);
testRecyclerAdapterInternal(TestModel.ID, new RecyclerAdapterTest() {
@Override
public void testRecyclerAdapter(TestRecyclerAdapter adapter) {
FrameLayout parent = new FrameLayout(ContextProvider.getContext());
TestViewHolder holder = adapter.onCreateViewHolder(parent, adapter.getItemViewType(0));
adapter.onBindViewHolder(holder, 0);
assertEquals(model1, holder.item);
assertEquals(model1.getDisplayName(), holder.textView.getText().toString());
adapter.onBindViewHolder(holder, 1);
assertEquals(model2, holder.item);
assertEquals(model2.getDisplayName(), holder.textView.getText().toString());
}
});
}
/**
* @return dialog view with picker inside
*/
@Override
protected View onCreateDialogView() {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
numPicker = new NumberPicker(getContext());
numPicker.setLayoutParams(layoutParams);
numPicker.setMinValue(minValue);
numPicker.setMaxValue(maxValue);
FrameLayout dialogView = new FrameLayout(getContext());
dialogView.addView(numPicker);
return dialogView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get references to a background containers
final FrameLayout top = findViewById(R.id.top_frame);
final FrameLayout bottom = findViewById(R.id.bottom_frame);
// Get a reference to the ToggleButton
final ToggleButton toggleButton = findViewById(R.id.togglebutton);
// Set an setOnCheckedChangeListener on the ToggleButton
setListener(toggleButton, top);
// Get a reference to the Switch
final Switch switcher = findViewById(R.id.switcher);
// Set an OnCheckedChangeListener on the Switch
setListener(switcher, bottom);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View contentView = onCreateView(getActivity().getLayoutInflater());
if (contentView == null) {
dismiss();
return;
}
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
linearLayout.setLayoutParams(containerLayoutParams);
contentView.setLayoutParams(new LinearLayout.LayoutParams(-1, 0, 1));
linearLayout.addView(contentView);
container.addView(linearLayout);
}
@Override
public void onViewCreated(FrameLayout view) {
mClose = findViewById(R.id.close);
mClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DokitViewManager.getInstance().detach(UIPerformanceDisplayDokitView.class.getSimpleName());
DokitViewManager.getInstance().detach(UIPerformanceInfoDokitView.class.getSimpleName());
UIPerformanceManager.getInstance().stop();
}
});
mMaxLevelText = findViewById(R.id.max_level);
mMaxLevelViewIdText = findViewById(R.id.max_level_view_id);
mTotalTimeText = findViewById(R.id.total_time);
mMaxTimeText = findViewById(R.id.max_time);
mMaxTimeViewIdText = findViewById(R.id.max_time_view_id);
}
/**
* Restore map to original size and remove
* views associated with displaying route segments.
* @return MapFragment - The fragment containing the map
*/
public final MapFragment restoreMapAndRemoveRouteDetail(){
// Remove the route directions
final LinearLayout layout = findViewById(R.id.route_directions_container);
layout.setLayoutParams(new CoordinatorLayout.LayoutParams(0, 0));
layout.requestLayout();
// Show the map
final FrameLayout mapLayout = findViewById(R.id.map_fragment_container);
final CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
mapLayout.setLayoutParams(layoutParams);
mapLayout.requestLayout();
final FragmentManager fm = getSupportFragmentManager();
final MapFragment mapFragment = (MapFragment) fm.findFragmentById(R.id.map_fragment_container);
mapFragment.removeRouteDetail();
return mapFragment;
}
protected void setLeftMenuView(int viewWidth, int viewHeight){
View menu = getLeftMenuView();
if(menu == null)
return;
if(mLeftMenuStyle.mMenuBorderPercent >= 0f)
mLeftMenuStyle.mMenuBorder = (int)(viewWidth * mLeftMenuStyle.mMenuBorderPercent);
if(mLeftMenuStyle.mMenuOverDragBorderPercent >= 0f)
mLeftMenuStyle.mMenuOverDragBorder = (int)(viewWidth * mLeftMenuStyle.mMenuOverDragBorderPercent);
mLeftMenuStyle.mSize = viewWidth - mLeftMenuStyle.mMenuBorder;
if(mLeftMenuStyle.mCloseEdgePercent >= 0f)
mLeftMenuStyle.mCloseEdge = (int)(mLeftMenuStyle.mSize * mLeftMenuStyle.mCloseEdgePercent);
menu.setLayoutParams(new FrameLayout.LayoutParams(mLeftMenuStyle.mSize, FrameLayout.LayoutParams.MATCH_PARENT));
menu.setVisibility(mOffsetX <= 0 ? View.GONE : View.VISIBLE);
}
@Test
public void testAppNexusInvalidPrebidServerConfigId() throws Exception {
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
final OnCompleteListener[] listener = new OnCompleteListener[1];
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject = new MoPubView(m.getActivity());
adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("6ace8c7d-88c0-4623-8117-ffffffffffff", 300, 250);
OnCompleteListener l = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject);
adObject.loadAd();
}
};
listener[0] = spy(l);
adUnit.fetchDemand(adObject, listener[0]);
}
});
Thread.sleep(10000);
verify(listener[0], times(1)).onComplete(ResultCode.INVALID_CONFIG_ID);
}
@Override
public void handleStyledAttributes(TypedArray a) {
mRootContainer = new LinearLayout(getContext());
mRootContainer.setOrientation(LinearLayout.VERTICAL);
mHeaderContainer = new FrameLayout(getContext());
if (mZoomView != null) {
mHeaderContainer.addView(mZoomView);
}
if (mHeaderView != null) {
mHeaderContainer.addView(mHeaderView);
}
int contentViewResId = a.getResourceId(R.styleable.PullToZoomView_contentView, 0);
if (contentViewResId > 0) {
LayoutInflater mLayoutInflater = LayoutInflater.from(getContext());
mContentView = mLayoutInflater.inflate(contentViewResId, null, false);
}
mRootContainer.addView(mHeaderContainer);
if (mContentView != null) {
mRootContainer.addView(mContentView);
}
mRootContainer.setClipChildren(false);
mHeaderContainer.setClipChildren(false);
mRootView.addView(mRootContainer);
}
private static FrameLayout.LayoutParams convertEmptyViewLayoutParams(ViewGroup.LayoutParams lp) {
FrameLayout.LayoutParams newLp = null;
if (null != lp) {
newLp = new FrameLayout.LayoutParams(lp);
if (lp instanceof LinearLayout.LayoutParams) {
newLp.gravity = ((LinearLayout.LayoutParams) lp).gravity;
} else {
newLp.gravity = Gravity.CENTER;
}
}
return newLp;
}
public AndroidBug5497Workaround(Activity activity) {
if (activity!=null){
FrameLayout content = activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(listener);
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
}
private void init(Context context, AttributeSet attrs) {
this.context = context;
layoutInflater = LayoutInflater.from(context);
layoutInflater.inflate(R.layout.ease_widget_chat_input_menu, this);
primaryMenuContainer = (FrameLayout) findViewById(R.id.primary_menu_container);
emojiconMenuContainer = (FrameLayout) findViewById(R.id.emojicon_menu_container);
chatExtendMenuContainer = (FrameLayout) findViewById(R.id.extend_menu_container);
// extend menu
chatExtendMenu = (EaseChatExtendMenu) findViewById(R.id.extend_menu);
}
private void initView() {
FrameLayout container = (FrameLayout)getChildAt(0);
iv = (SimpleImageView)container.getChildAt(0);
pb = (ProgressBar)container.getChildAt(1);
tv = (SimpleTextView)getChildAt(1);
iv.setImageDrawable(getResources().getDrawable(R.drawable.ptr_down_arrow));
}
protected void registerDrawer() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if(iDrawerClosedCallBack != null){
iDrawerClosedCallBack.onDrawerClosed();
}
}
};
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
tintNavView(ThemeController.getCurrentColor().mainColor);
headerLayout = (FrameLayout) LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
ImageView imageView=(ImageView)headerLayout.findViewById(R.id.nav_header_back);
imageView.setImageDrawable(ImageProcessor.zoomImageMin(
ContextCompat.getDrawable(this, R.drawable.navigation_header)
, getResources().getDisplayMetrics().widthPixels
, getResources().getDisplayMetrics().widthPixels));
navigationView.addHeaderView(headerLayout);
}
private void addRefreshableView(Context context, T refreshableView) {
mRefreshableViewWrapper = new FrameLayout(context);
mRefreshableViewWrapper.addView(refreshableView, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
addViewInternal(mRefreshableViewWrapper, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
}
@Before
public void setUp() {
tabContainer = new FrameLayout(InstrumentationRegistry.getContext());
tab = new BottomBarTab(InstrumentationRegistry.getContext());
tabContainer.addView(tab);
}
private void slideTo(float translationY, final boolean animated) {
ViewHelper.setTranslationY(mInterceptionLayout, translationY);
if (translationY < 0) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
lp.height = (int) -translationY + getScreenHeight();
mInterceptionLayout.requestLayout();
}
}
public NotificationWallpaper(FrameLayout container, XSharedPreferences prefs) throws Throwable {
mNotificationPanelView = container;
mContext = mNotificationPanelView.getContext();
mBackupBg = mNotificationPanelView.getBackground();
Context gbContext = Utils.getGbContext(mContext);
mNotifBgImagePathPortrait = gbContext.getFilesDir() + "/notifwallpaper";
mNotifBgImagePathLandscape = gbContext.getFilesDir() + "/notifwallpaper_landscape";
initPreferences(prefs);
createHooks();
prepareWallpaper();
}
private void init() {
setOrientation(VERTICAL);
mTitleViewGroup = new FrameLayout(getContext());
mTitleViewGroup.setId(DEFAULTTITLEPARENTRESID);
addView(mTitleViewGroup);
mContentViewGroup = new FrameLayout(getContext());
mContentViewGroup.setId(DEFAULTCONTENTPARENTRESID);
addView(mContentViewGroup);
}
public static void attachBadgeDrawable(
@NonNull BadgeDrawable badgeDrawable,
@NonNull View anchor,
@Nullable FrameLayout compatBadgeParent) {
setBadgeDrawableBounds(badgeDrawable, anchor, compatBadgeParent);
if (USE_COMPAT_PARENT) {
if (compatBadgeParent == null) {
throw new IllegalArgumentException("Trying to reference null compatBadgeParent");
}
compatBadgeParent.setForeground(badgeDrawable);
} else {
anchor.getOverlay().add(badgeDrawable);
}
}
@Override
public void initUIHandles() {
// TODO Auto-generated method stub
llHead = (LinearLayout)findViewById(R.id.ll_head);
ivHeadTitle = (ImageView)findViewById(R.id.iv_head_title);
ivHeadCart = (ImageView)findViewById(R.id.iv_head_cart);
ivHeadMenu = (ImageView)findViewById(R.id.iv_head_menu);
tvCartNotif = (TextView)findViewById(R.id.tv_cart_notif);
flBody = (FrameLayout)findViewById(R.id.ll_body);
tf = Typeface.createFromAsset(getAssets(), "icomoon.ttf");
}
public static void updateGroupViewVisibility(FormEntryActivity activity,
boolean hasGroupLabel,
boolean shouldHideGroupLabel) {
FrameLayout header = activity.findViewById(R.id.form_entry_header);
TextView groupLabel = header.findViewById(R.id.form_entry_group_label);
updateGroupViewVisibility(header, groupLabel, hasGroupLabel, shouldHideGroupLabel);
}