CSS在嵌套div上出现border-radius错误(CSS wrong appearance of border-radius on a nested div)
使用以下HTML我需要:
确保
target div
(粉红色)的边框与wrapper-target
红色边框div相邻。必须适用于border-radius的任何值。
考虑到:
- 我正在使用
box-sizing: border-box;
但也可以重置为默认值。- 我无法更改
target
div的border-radius
属性。*, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
<div id="wrapper-target" style="position:absolute;top:100px;left:100px;width:250px;height:250px;border-radius:50px;border:25px solid red;"> <div id="target" style="position:relative;width:100%;height:100%;background-color:plum;border-radius:inherit"> </div> </div>
笔记:
- 我不需要在这个具体的例子中创建一个圆圈:)。
Using the following HTML I need to:
Make sure that the border of
target div
(pink) is adjacent of thewrapper-target
red border div.Must work on any value of border-radius.
Considering that:
- I am using
box-sizing: border-box;
but can be also reset to a default value.- I cannot change the
border-radius
property of thetarget
div.*, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
<div id="wrapper-target" style="position:absolute;top:100px;left:100px;width:250px;height:250px;border-radius:50px;border:25px solid red;"> <div id="target" style="position:relative;width:100%;height:100%;background-color:plum;border-radius:inherit"> </div> </div>
NOTES:
- I do not need to make a circle in this specific example :).
原文:https://stackoverflow.com/questions/35984449
最满意答案
我也会在这个要求上推荐
Fragment
,但是由于你的应用程序已经实现,你可以采用这种方法。all the activities that exists before it in the stack should be finished.
Android
不提供任何标记来清除以下所有Activities
如使用clearTop
清除热门Activities
。 这将是简单的,如果我们有clearBottom
:)好。 如果您
Android API version from 16
定位Android API version from 16
,则此方法将以优化的方式提供帮助。 对于其他较低版本,您需要分别完成每个Activity
。创建一个将所有
Activity
实例添加到HashMap
的BaseActivity
(类似于将Fragments to back Stack
添加Fragments to back Stack
)。 但这里只是记住堆栈中的Activities
。 您也可以使用ActivityManager.RunningTaskInfo
检查堆栈中的ActivityManager.RunningTaskInfo
但我不想让它更复杂。声明一个静态变量。 我更喜欢在我的
Application class
做。public class MyApp extends Application { public static HashMap<String , CommonActivity > mBackStackActivities = new HashMap<String, CommonActivity>(); }
现在,当一个
Activity created
的Activity created
将其实例添加到HashMap
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyApp.mBackStackActivities.put(getComponentName().getClassName(), this); }
并且,在
Activity destroy
时将其Activity destroy
@Override protected void onDestroy(){ MyApp.mBackStackActivities.remove(getComponentName().getClassName()); super.onDestroy(); }
现在,
Override
base Activity class
的startActivity
方法,并在Activity
开始时check if the
HashMap中check if the
exists in
Activity. If exists
. If exists
all the below
using
finishAffinity完成all the below
Activity。@Override public void startActivity(Intent intent) { if(MyApp.mBackStackActivities .containsKey(intent.getComponent().getClassName())){ if(android.os.Build.VERSION.SDK_INT >= 16) { Activity activity = MyApp.mBackStackActivities.get(intent.getComponent().getClassName()); // finish the activity as well as all the below Activities. activity.finishAffinity(); // supported from API 16 }else { // loop through all the below activity and finish it } } super.startActivity(intent); }
最后,如果您需要为清单中的所需
Activities
设置android:taskAffinity
,则默认情况下所有Activities
都将具有相同的亲和力名称(包名称)。 如果您希望涵盖所有Activities
,则可以离开此项。<activity android:name="com.example.app.activities.MainActivity" android:label="@string/title_activity_common" android:taskAffinity="@string/task_affinity_name"> </activity>
在字符串xml中
<string name="task_affinity_name">com.example.app.affinity</string>
注意:如上所述的较低版本,您需要单独完成每个
Activity
在这里找到完整的源https://gist.github.com/androidbensin/7d9261fd148c15575dd1
I would also recommend
Fragment
on this requirement , but since your application is already implemented, you can go with this approach.all the activities that exists before it in the stack should be finished.
Android
doesn't provide any flag to clear all the belowActivities
like clearing topActivities
usingclearTop
. It would be simple if we hadclearBottom
:)Ok. If your targeting
Android API version from 16
, this approach will help in an optimized way. For the other lower version you need to finish eachActivity
individually.Create a
BaseActivity
which will add all theActivity
Instance into aHashMap
(similar to addingFragments to back Stack
). But here this is to just remember theActivities
in stack. You can also check theActivities
in stack usingActivityManager.RunningTaskInfo
but I don't want to make it more complex.Declare a static variable. I prefer to do in my
Application class
.public class MyApp extends Application { public static HashMap<String , CommonActivity > mBackStackActivities = new HashMap<String, CommonActivity>(); }
Now, when an
Activity created
add its instance to theHashMap
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyApp.mBackStackActivities.put(getComponentName().getClassName(), this); }
And,remove it when the
Activity destroy
@Override protected void onDestroy(){ MyApp.mBackStackActivities.remove(getComponentName().getClassName()); super.onDestroy(); }
Now,
Override
thestartActivity
method inbase Activity class
and when anActivity
is startedcheck if the
Activityexists in
HashMap. If exists
finishall the below
Activityusing
finishAffinity`.@Override public void startActivity(Intent intent) { if(MyApp.mBackStackActivities .containsKey(intent.getComponent().getClassName())){ if(android.os.Build.VERSION.SDK_INT >= 16) { Activity activity = MyApp.mBackStackActivities.get(intent.getComponent().getClassName()); // finish the activity as well as all the below Activities. activity.finishAffinity(); // supported from API 16 }else { // loop through all the below activity and finish it } } super.startActivity(intent); }
Finally, If you need to set
android:taskAffinity
in manifest for the requiredActivities
, by default all theActivities
will have same Affinity name (the package name). You can leave this if you want all yourActivities
to be covered.<activity android:name="com.example.app.activities.MainActivity" android:label="@string/title_activity_common" android:taskAffinity="@string/task_affinity_name"> </activity>
In string xml
<string name="task_affinity_name">com.example.app.affinity</string>
Note : As said above for lower version , you need to finish each
Activity
Individually`Find the complete source here https://gist.github.com/androidbensin/7d9261fd148c15575dd1
相关问答
更多-
There are many outdoor(户外的) a in spring.根据句[2022-09-23]
activities -
我会将适配器放在adapters包中。 即使it is small adapter, mostly its to be used within a activity in a dialog, with operations reflecting back to activity您将永远不会知道适配器将如何发展以及它将在何种情况下使用。 关于你的担忧: Too much of context references - 您的适配器的每个实例都会有一个单独的Context来引用。 只要你没有从你的适配器泄漏任何东 ...
-
我也会在这个要求上推荐Fragment ,但是由于你的应用程序已经实现,你可以采用这种方法。 all the activities that exists before it in the stack should be finished. Android不提供任何标记来清除以下所有Activities如使用clearTop清除热门Activities 。 这将是简单的,如果我们有clearBottom :) 好。 如果您Android API version from 16定位Android API ...
-
我在我的应用程序中发现,每个Activity都通常负责一个UI视图。 因此,不是加载和卸载不同的布局,这可能会变得非常混乱,最好将每个子活动分成它自己的Activity类并使用显式意图(明确指定目标活动的意图,而不是依赖于意图过滤器)在他们之间移动。 I've found in my applications that each Activity is generally responsible for a single UI view. So rather than loading and unloadi ...
-
Android:用于更新UI的异步网络活动的任何实践(Android: Any practices for asyncronous network activities which updates UI)[2023-09-02]
我建议使用你提到的接收器,并检测用户正在观看的活动,我会在每个活动中使用onResume和onPause方法将当前的一个存储在sqlite数据库中。 I would suggest to use receivers as you mentioned, and to detect in which activity the user is watching I would use the onResume and onPause methods in each activity to store the cu ... -
您可以在AndroidManifest的活动中添加android:configChanges="orientation"以通知操作系统您正在处理方向更改。 通常我们会在onConfigurationChanged方法中实现某种处理,但在这种情况下,你什么都不做。 You can add android:configChanges="orientation" on the activity in the AndroidManifest to inform the OS that you are handlin ...
-
Android中的多项活动(Multiple Activities in Android)[2023-12-10]
问题是您需要在调用setContentView()之后在方法内设置views 。 这些 ImageButton ibHome2 = (ImageButton) findViewById(R.id.ibHome2); Button bTempConvert = (Button) findViewById(R.id.bTempConvert); EditText etCel = (EditText) findViewById(R.id.etCel); EditText etFah = ( ... -
单活动应用程序是可能的,但不一定是最佳实践。 恕我直言,片段有一个非常复杂的生命周期,所以当你不必使用片段时使用Activituies。 如果您的问题是通过活动共享抽屉片段的状态,您可以将其作为额外的活动传递给每个活动,或者将其保存在静态类/变量中以在每次启动时检索它。 不要忘记在破坏您的某项活动期间保存此状态。 Single Activity applications are possible, but are not necessarily a best practice. IMHO, fragment ...
-
我面临的问题是为主机应用程序提供一个简单的API来定义在每种情况下要路由到的活动。 我认为只是允许他们在onActivtyResult中处理它,但库中的某些场景可能看起来像这样... 我没有看到onActivityResult方法存在任何问题,您可以简单地链接这些调用,然后返回到[host activity#1] ,这将决定接下来的导航位置。 如果你害怕编写太多的代码(我认为你不应该这样做),你可以考虑这个解决方法:创建一个覆盖onActivityResult()的基类活动类。 它将所有导航逻辑集中在一个地 ...
-
如何分开活动(How to separate activities)[2024-02-04]
@Mahfa通过他发布的链接让我走上了正确的轨道,最终我找到了这个代码示例,解决了我的问题http://www.programcreek.com/java-api-examples/index.php?source_dir=jdkernel-更新主/ SRC / jdkernel / UI / ThemeListNewActivity.java 这是我完成的代码: public void onActivityResult(int requestCode, int resultCode, Intent dat ...