android - android布局单独的资源文件夹
问题描述
假设我在 res/layout 中有一个文件
<com.dog.cat.SomeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="Overdraw"
android:id="@+id/SomeView"
style="@style/SomeStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
我想要一个类似 res/layout-sw600dp 的布局
<com.dog.cat.SomeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="Overdraw"
android:id="@+id/SomeView"
style="@style/SomeStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding_left="10dp"
/>
我只在第二个文件中添加了 android:padding_left="10dp" 。有没有办法将第一个文件添加到第二个文件而不像这样重新输入所有其他属性?
<com.dog.cat.SomeLayout
//include all attributes in one line
android:padding_left="10dp"
/>
解决方案
您可以创建另一种样式,例如:
<style name="SomeStyle.SixHundredDP">
//Put other attributes here
<item name="android:paddingLeft">10dp</item>
</style>
现在在 res/layout-sw600dp 中进行布局:
<com.dog.cat.SomeLayout
//Other attributes for this view
style="@style/SomeStyle.SixHundredDP"
/>
您也可以为不同的屏幕尺寸设置不同的值文件夹,就像布局一样。例如看到这个。
推荐阅读
- python - 为什么可嵌入的 Python 发行版无法定位原生模块?
- python - 使用反向传播算法进行分类
- javascript - 在Javascript中,如何将1个变量生成的数字组合成一个数组
- python - 在 django 中调用回调 URL 时出现 Forbidden (403) 错误
- xamarin.forms - 在 google play 上发布 xamarin 应用程序的问题
- sql - 在 Pivot 块中获取无效标识符 ORA-00904
- javascript - 命令处理程序丰富的嵌入类型错误:无法读取未定义的属性“发送”
- google-apps-script - 将公式添加到列中的空白单元格
- python - 如何在 Python 中读取多行输入?
- recursion - Clojure:你能在递归函数中连接吗?