这是我的 jsFiddle 对于以下问题: http: //jsfiddle.net/arelia/Rruxf/
我希望页眉位于正文的最顶部,页脚位于正文的最底部。我在页眉和页脚之间有一个内容 div(位置:相对),当我在 div 周围设置边距时,我绝对定位的页眉和页脚从其顶部/底部位置移动该边距的高度(当我尝试在 div 中的段落上方和下方设置边距)。在小提琴中,您可以看到页脚没有附加到底部,即使它是绝对定位的(我继续将页眉设为静态,因为静态给出了预期的结果)。如何将页眉和页脚定位到正文的顶部和底部,而不让中间的内容移动这两个元素?如果position:absolute元素被移出流,为什么会影响它们的位置呢?
我尝试在这里和谷歌搜索“CSS边距影响绝对值”和其他一些短语,但无济于事。我在开发者工具中进行更多尝试时发现了这一点:
我正在使用 viewpager 来显示文件夹的内容。在页面之间我有 96 像素的页边距。为了处理配置更改,我在 AndroidManifest.xml 中添加了以下几行:
<activity
android:name="SimpleFilePreviewerActivity"
android:configChanges="keyboardHidden|orientation|screenSize" >
</activity>
Run Code Online (Sandbox Code Playgroud)
从最左边的页面开始,当我旋转我的设备时,一切都会根据需要进行处理。然而,在接下来的页面上,旋转后视图不再以屏幕为中心,而是有一个偏移,当 ViewPager 向右滑动时,它会变得更糟。
当屏幕旋转后触摸屏幕时,显示的视图将重新居中。此偏移仅在页边距设置为大于 0 时发生。
这是一个已知的错误?有没有办法遇到这个偏移问题?
提前致谢,
弗洛
我在 Visual Studio 2012 和 WPF 方面遇到了最烦人的问题,我希望得到一些帮助。我有一个带有子元素的简单网格,例如带有网格单元格的 TextBlocks。文本块被设置为在单元格内相对定位(例如,使用左侧的水平对齐)。一切都很好,直到我敢于调整网格的列或行的大小。然后,Visual Studio 插入边距和宽度/高度属性,以与父/子元素的结果位置保持一致。这一切都悄无声息地发生,直到后来我决定进一步减小列的大小时我才注意到,突然 TextBlock 由于插入了其 Margin 属性而被剪裁。我必须检查每个子元素并手动删除这些额外的属性。我必须在当前的项目中执行此操作近 100 次,而且我无法在网络上找到任何内容来了解如何告诉 Visual Studio 后退并停止采取这些窃取我想要实现的良好格式的自由行为。这是一个代码片段供参考。但我的项目中许多不同的网格实例都发生过这种情况。
<Grid Canvas.Left="435" Canvas.Top="138" Height="61" Width="192">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="11*"/>
<ColumnDefinition Width="21*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Subtotal:" HorizontalAlignment="Right" VerticalAlignment="Center" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
...调整第 0 列的大小后:
<TextBlock Grid.Row="0" Grid.Column="0" Text="Subtotal:" HorizontalAlignment="Right" VerticalAlignment="Center" Height="16" Margin="0,7" Width="47" />
Run Code Online (Sandbox Code Playgroud)
当然还有其他人遇到过这个问题。请帮忙!
谢谢
这很奇怪,但是在 Java 代码中设置左边距或右边距在某些设备/平台上不起作用。
这是代码。简单的xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<View
android:id="@+id/myView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:background="#00ff00" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
爪哇:
@Override
public void onConfigurationChanged (Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)findViewById(R.id.myView).getLayoutParams();
params.leftMargin = 50;
params.rightMargin = 50;
params.topMargin = 50;
params.bottomMargin = 50;
findViewById(R.id.myView).requestLayout();
}
}
Run Code Online (Sandbox Code Playgroud)
所以我在 FrameLayout 中有一个绿色的视图。在旋转时,我会更改视图的边距。(我的活动有 android:configChanges="orientation|screenSize")
结果如下:
三星 Galaxy S 3 (Android 4.1.2)(工作正常)


索尼爱立信 Xperia Arc S (Android 4.0.4)(工作奇怪!)


正如您在代码中看到的,在 Android 4.1.2 上正常工作。而在 Android 4.0.4 上没有设置左右边距,而是设置了上边距。为什么要顶?
我已经在模拟器上测试过了。所有平台 >= Android 4 …
这个问题更多地是关于 apply 函数中的 MARGIN 参数而不是任何东西。假设我想将以下矩阵乘以以下向量,以便我将第一个矩阵元素乘以第一个向量元素,第二个乘以第二个,依此类推。我使用以下代码:
matrix <- matrix(1:10)
vector <- c(10:19)
t(apply(matrix,2,'*',vector))
Run Code Online (Sandbox Code Playgroud)
返回一个非常干净的结果:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 10 22 36 52 70 90 112 136 162 190
Run Code Online (Sandbox Code Playgroud)
但是如果我改变 MARGIN = 2,我会得到这个结果:
matrix <- matrix(1:10)
vector <- c(10:19)
t(apply(matrix,1,'*',vector))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 10 11 12 13 14 15 16 17 18 19
[2,] 20 22 24 26 28 30 32 34 36 38
[3,] 30 33 …Run Code Online (Sandbox Code Playgroud) 我一直在拉我的头发反对这个左边的填充/边距只是不要消失问题,即将成为秃头......对此的解决方案将不胜感激!我已经尝试过 SO 的这些答案,它确实移动了一些填充,但不是全部。基本上所有的答案都说将 contentInsetStart 和 contentInsetLeft 设置为 0dp。这确实删除了左侧的一些填充,但我仍然看到一个填充,它只是比我将 contentInsetStart 和 contentInsetLeft 设置为 0dp 之前小。此解决方案适用于三星手机,但不适用于我测试过的任何平板电脑,例如 Nexus 7、Nexus 9、Dell Venus 8 等。

我相信很多人都有这个问题,这些是我尝试过的答案,但仍然在上面显示的左侧留下填充/边距。
Android Lollipop、AppCompat ActionBar 自定义视图不占用整个屏幕宽度
我的活动/操作栏左侧的填充/边距 - 不知道它来自哪里,无法删除它
如何在 ActionBar 上移除应用程序图标和屏幕边缘之间的边距?
样式
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/AppThemeActionBar</item>
<item name="logo">@android:color/transparent</item>
</style>
<style name="AppThemeActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="displayOptions">showCustom</item>
<item name="background">@color/blue</item>
<item name="actionBarSize">50dp</item>
<item name="height">50dp</item>
<item name="contentInsetLeft">0dp</item>
<item name="contentInsetStart">0dp</item>
<item name="contentInsetEnd">0dp</item>
<item name="android:layout_marginLeft">0dp</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
活动布局,activity_main.xml,它几乎是空的,只是主要活动类的虚拟布局,自定义操作栏视图位于另一个布局文件中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) 我注意到一个 Xcode 警告说:
“iOS 11.0 之前的语言方向布局边距”
甚至这个问题在Apple 开发者论坛上也没有得到解答。
我使用过故事板和警告不会导致任何特定视图。
原因是什么或有什么解决办法?
我用翻译器。我的意见不能准确传递。
ul {
display: flex;
overflow-x: auto;
border: 1px solid aqua;
background-color: tomato;
width: 400px;
list-style:none;
padding-left:0px;
}
li {
border: 1px solid Aquamarine;
min-width: 300px;
margin: 10px;
}Run Code Online (Sandbox Code Playgroud)
<ul>
<li>item1</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
</ul>Run Code Online (Sandbox Code Playgroud)
https://codepen.io/anon/pen/bLJREL
与我试图做的不同,最后一个元素没有边距。
如果您想在 'item4' 元素后添加边距怎么办?
我在 ChipGroup 中有 Chips,在 HorizontalScrollView 中有这个 ChipGroup。但我的问题是最后一个芯片上的 marginEnd 不工作!
我尝试以编程方式更改布局参数,但没有成功
<HorizontalScrollView
android:id="@+id/chips_container"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/dividerSmartReplies"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:chipSpacing="8dp"
app:singleLine="true"
app:singleSelection="true">
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginStart="8dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginEnd="8dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
最后一个芯片后我需要额外的空间。ChipGroup 的 padding 有效,但没有预期的 …
我正在阅读关于 Margin Collapsing 的文章,我发现了这个:margin
相邻兄弟姐妹 相邻兄弟姐妹的边距被折叠(除非后一个兄弟姐妹需要清除浮动)。
我不明白最后一句话“除非后一个兄弟需要清除浮动”。有人可以举个例子吗?
谢谢