组布局中的边距似乎不起作用.
例如,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="40dip"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="I'm a button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
应显示一个四边有40p边距的按钮.但是,它在右侧和底部有80p的边距.
难道我做错了什么?这是一个错误吗?
解决方法是使用重力,但这只适用于均匀的边距.
顺便说一句,这里有一个类似的问题,但尚未得到解答.
是否有任何理由为什么以下layout_marginBottom不起作用?但是,如果我在第二个视图上使用layout_marginTop,它确实可以正常工作
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ade4ad">
<TextView
android:id="@+id/first"
android:layout_width="90dp"
android:layout_height="40dp"
app:layout_marginBottom="10dp"
android:background="#000"/>
<TextView
android:id="@+id/second"
android:layout_width="90dp"
android:layout_height="40dp"
android:background="#fff"
app:layout_constraintTop_toBottomOf="@+id/first"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我更喜欢边距最小的按钮,与文本标题一样宽.有没有办法在Swing中的JButton中实现这一点?
我现在在实践中看到的是,即使我尝试使用setMaximumSize()和类似的东西,它最终也会吃掉文本标题,将其剪切到右边.但它并没有降低利润率.
对于Android平台:
我需要在listview中的垂直滚动条的右侧放置边距(它是自定义的).请参阅附图.默认滚动条粘贴到列表视图的右侧.

需要你的手.谢谢.
这是main_alllatestnews.xml的一部分
<LinearLayout
android:id="@+id/layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/layout_menu"
android:layout_below="@id/layout_title"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这里充满了main_alllatestnewslist.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_temp"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="@drawable/background_news_list" >
<ImageView
android:id="@+id/image_alllatestnewstitle"
android:layout_width="134px"
android:layout_height="80px"
android:layout_marginBottom="5px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginTop="5px"
android:scaleType="centerCrop" />
<LinearLayout
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/text_particularlatestnewstitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="25px" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25px" >
<TextView
android:id="@+id/text_newsdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#999999"
android:textSize="15px" />
<TextView
android:id="@+id/text_newscategorytitle"
android:layout_width="50px"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:gravity="right"
android:textColor="#ff0000"
android:textSize="15px" />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是main_alllatestnews.java的一部分
LayoutInflater liInflater = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
linear.addView(liInflater
.inflate(R.layout.main_alllatestnewslist, …Run Code Online (Sandbox Code Playgroud) 在CSS中,保证金顺序是:右上角左下角
在XAML中,保证金顺序为:左上方左下方
有没有理由为什么WPF团队没有将这与CSS规范对齐?
当这套聪明的规则有所帮助时,无法弄清楚情况.它们打破了盒子模型的简单性,并在将不同的布局组合在一起时提供无限的麻烦来源.那是什么原因?
参考规则.
更新:规则对于兄弟元素是非常合乎逻辑的,但为什么边距应该传播到父元素直到树?解决了什么样的问题?
例如:
<div style="margin: 20px; background-color: red;">
<div style="margin: 20px;">
<p style="margin: 100px;">red</p>
</div>
</div>
<div style="margin: 20px; background-color: blue;">blue</div>
Run Code Online (Sandbox Code Playgroud)
顶级div相互间隔100px.
我有2个嵌套的div应该是100%宽.不幸的是,带有Textbox的内部div溢出并且实际上比外部div大.它有一个左边距,溢出大约边距的大小.
我该如何解决这个问题?
<div style="width:100%;">
<div style="margin-left:45px; width:100%;">
<asp:TextBox ID="txtTitle" runat="server" Width="100%"></asp:TextBox><br />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如果我不做100%,那么文本框不是100%宽.
我有一个"容器" div我给了margin:auto;它只要我给它一个特定的工作正常width,但现在我改变它inline-block并且不margin:auto;工作
#container {
border: 1px solid black;
height: 500px;
width: 650px;
}
.MtopBig {
margin-top: 75px;
}
.center {
margin-left: auto;
margin-right: auto;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
#container {
border: 1px solid black;
display: inline-block;
padding: 50px;
}
.MtopBig {
margin: 75px auto;
position: relative;
}
.center {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)

我想删除这两个元素之间的额外空间.我试过但不能这样做.这是保证金崩溃的问题吗?
怎么解决这个问题?如何删除多余的空间?
这是我的HTML:
<div id="output">
<i>
<span id="grade">Your grade :</span>
<span id="total"></span>
<span id="max"></span>
<center><h1><span id="percentage"></span></h1></center>
</i>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的css:
body
{
width:250px;
height:100px;
background : #F2F2F2;
}
#output
{
font-family : roboto light ;
color : #A4C639;
font-size : 30px;
}
#grade
{
font-size : 25px;
color : black;
}
#max
{
color : black;
}
#percentage
{
background : #A4C639;
color : #FFFFFF;
padding : 15px;
border-radius : 15px;
}
Run Code Online (Sandbox Code Playgroud)