在二层列表中使用的XML布局的改变保证金 [英] Change Margin of a Layout using XML in Layer-List
问题描述
我尝试了几种选择,但我无法找到要做到这一点的最好办法:我想换一个线性布局的保证金使用XML按钮被点击时这是我的code所选按钮:
I tried several options but I can't find the best way to do this: I want to change the margin of a Linear Layout when button is clicked using XML. Here's my code for the selected button:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="-1dp">
<shape android:shape="rectangle" >
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<solid android:color="#424346" />
<stroke
android:width="1dp"
android:color="#2d2e2f" />
</shape>
</item>
</layer-list>
现在我想补充保证金,如果它放在一个单独的文件应该是这样的变化:
Now I want to add the changing of margin which if put in a separate file would look like this:
<resources>
<style android:id="@+id/tab_label" >
<item android:layout_marginTop="7dp"/>
</style>
</resources>
我试图将其添加为到图层列表中的项目,但它返回一个错误。
I tried adding it as an item to the layer list but it returns an error.
把它在另一个文件是很成问题,因为Android的不能让两种风格在一个元素中使用。所以我想了两件事情合并在一个XML文件中。
Putting it in another file is quite problematic because Android can't allow two styles to be used in one element. So I want to merge the two things in one XML file.
或者,有什么这样做的最佳方式?
Or, what's the best way doing this?
推荐答案
只是大致经过一个星期的试验解决了这个问题。在此行中code的:
Just solved it after roughly a week of trials. On this line of code:
<item android:bottom="-1dp">
修改为这样的:
<item android:bottom="-1dp" android:top="4dp">
您可以根据您的preference定制的数量。
You can customize the the number based on your preference.
这篇关于在二层列表中使用的XML布局的改变保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!