我将自定义样式应用于我的NavigationView:
app:theme="@style/NavigationDrawerStyle"
在我的styles.xml中:
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item>
<item name="android:listPreferredItemHeightSmall">50dp</item>
<item name="listPreferredItemHeightSmall">50dp</item>
</style>
但是,无论我插入自定义样式的dp值如何,我使用的图标都不会改变大小。它所做的只是缩放每个项目所占用的空间,两个选项之间的空间增加等,但图标大小是固定的。我找不到任何选项/属性来修改图标大小。我该怎么做?
这是我正在使用的示例图标:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="73dp"
android:height="93dp"
android:viewportWidth="73.79"
android:viewportHeight="93.25">
<path
android:pathData="M73.06,9.52 L36.9,0 0.74,9.52s-9,67.56 36.16,83.74C82.1,77.08 73.06,9.52 73.06,9.52Z"
android:fillColor="#2980b9"/>
<path
android:pathData="M36.9,0V93.25C-8.3,77.08 0.74,9.52 0.74,9.52Z"
android:fillColor="#3498db"/>
<path
android:pathData="M36.9,44.25m-25.69,0a25.69,25.69 0,1 1,51.38 0a25.69,25.69 0,1 1,-51.38 0"
android:fillColor="#2c3e50"/>
<path
android:pathData="M36.9,23a10,10 0,1 1,-10 10A10,10 0,0 1,36.9 23Z"
android:fillColor="#ecf0f1"/>
<path
android:pathData="M56.78,60.51a25.69,25.69 0,0 1,-39.77 0,21.31 21.31,0 0,1 39.77,0Z"
android:fillColor="#ecf0f1"/>
</vector>
编辑:我还希望能够单独指定高度和宽度,如果可能的话。
答案 0 :(得分:1)
我重新格式化了一个问题作者的例子,从android到svg,以试图解释缩放原理。
width="73" height="93" viewBox="0 0 73 93"
width
和height
是viewport
- 我们在小工具展示中看到的区域。
viewport / viewBox
的比例决定了图标图像的比例。
在我们的例子中,比例为M1:1
也就是说,图标将显示为73 x 93
在增加viewport
时,请说两次width = "146"
height = "186"
比例为 - viewport / viewBox = 2
图标图像也会加倍
示例中的视口显示区域是红框。
绿色框的示例表示尝试通过容器样式更改图标的大小。
<style>
#container-Green {
display:block;
width:146;
height:186;
outline: 1px solid green;
}
</style>
<div id="container-Green">
<svg width="73" height="93" viewBox="0 0 73 93" style="border:1px solid red;" >
<g id="icon">
<path d="M73.06,9.52 L36.9,0 0.74,9.52s-9,67.56 36.16,83.74C82.1,77.08 73.06,9.52 73.06,9.52Z"
fill="#2980b9"/>
<path d="M36.9,0V93.25C-8.3,77.08 0.74,9.52 0.74,9.52Z"
fill="#3498db"/>
<path d="M36.9,44.25m-25.69,0a25.69,25.69 0,1 1,51.38 0a25.69,25.69 0,1 1,-51.38 0"
fill="#2c3e50"/>
<path
d="M36.9,23a10,10 0,1 1,-10 10A10,10 0,0 1,36.9 23Z"
fill="#ecf0f1"/>
<path
d="M56.78,60.51a25.69,25.69 0,0 1,-39.77 0,21.31 21.31,0 0,1 39.77,0Z"
fill="#ecf0f1"/>
</g>
</svg>
</div>
&#13;
结论:
viewport
或viewBox
<style>
#container-Green {
display:block;
width:30%;
height:30%;
outline: 1px solid green;
}
</style>
<div id="container-Green">
<svg width="30%" height="30%" viewBox="0 0 73 93" style="border:1px solid red;" >
<g id="icon">
<path d="M73.06,9.52 L36.9,0 0.74,9.52s-9,67.56 36.16,83.74C82.1,77.08 73.06,9.52 73.06,9.52Z"
fill="#2980b9"/>
<path d="M36.9,0V93.25C-8.3,77.08 0.74,9.52 0.74,9.52Z"
fill="#3498db"/>
<path d="M36.9,44.25m-25.69,0a25.69,25.69 0,1 1,51.38 0a25.69,25.69 0,1 1,-51.38 0"
fill="#2c3e50"/>
<path
d="M36.9,23a10,10 0,1 1,-10 10A10,10 0,0 1,36.9 23Z"
fill="#ecf0f1"/>
<path
d="M56.78,60.51a25.69,25.69 0,0 1,-39.77 0,21.31 21.31,0 0,1 39.77,0Z"
fill="#ecf0f1"/>
</g>
</svg>
</div>
&#13;
结论:
viewport
的值设置为百分比时,图标图像
有回应。 viewport
的百分比或父级的百分比
容器 我最喜欢的主题是svg,inrode我更明白了。
但在了解了缩放如何工作之后,您可能可以将我的示例从svg重新格式化为android。
很少搜索android中的百分比值主题:
看,可以帮到你:
<android.support.percent.PercentFrameLayout
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">
<Button
android:background="#f0f0f0"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%" />
</android.support.percent.PercentFrameLayout>
要连接库,请将依赖项添加到应用程序的build.gradle
文件的依赖项部分:
compile 'com.android.support:percent:23.0.0'
23.0.0 - 库的当前最新版本可能会随时间而变化。