1
A
回答
2
定义绘制资源文件中像这样
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="180"
android:endColor="@color/your_color"
android:startColor="@color/your_color2"
android:type="linear" />
</shape>
,并以此为背景的查看
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:id="@+id/view"
android:background="@drawable/your_gradient"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="30"
android:id="@+id/percentageTextview"
/>
</FrameLayout>
and on your activ ity使用这个
View background = (View) findViewById(R.id.view);
TextView textView = (TextView) findViewById(R.id.percentageTextview);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
int screenWidthInPix = displayMetrics.widthPixels;
ViewGroup.LayoutParams params = background.getLayoutParams();
params.width = (screenWidthInPix * Integer.parseInt(textView.getText().toString()))/100;
background.setLayoutParams(params);
+0
非常感谢你! – wallah
相关问题
- 1. 如何提供RAPHAEL条形图的背景图像
- 2. 条形图背景
- 3. 如何仅为背景提供类名?
- 4. 如何为ScrollContentPresenter提供背景色?
- 5. 如何为GtkEventBox提供透明背景?
- 6. 如何为背景图片提供替代和标题?
- 7. Heroku不提供背景图片,localhost呢?
- 8. Cocos2d为图层添加背景图片?
- 9. 你如何在背景中制作不同层次的图像?
- 10. 使层次条形图垂直
- 11. 如何覆盖css提供背景图片?
- 12. 如何在CSS中提供背景图片?
- 13. Pentaho CDE:为每个条形图条形图提供不同的数据源
- 14. 如何在Bootstrap中为行提供背景?
- 15. 如何仅为特定的div或类提供背景视频。
- 16. 如何为线性布局提供两种不同的背景
- 17. 如何在Highcharts条形图中设置全长背景?
- 18. 如何在android中更改条形图的背景颜色?
- 19. 如何在条形图中删除背景网格?
- 20. 如何在简单的条形图上移除白色背景?
- 21. 如何更改amCharts条形图气球的背景颜色?
- 22. IOS,如何清除背景图形
- 23. 如何使用C#提供SVG,使其呈现为CSS背景图像
- 24. 如何在IE9中正确提供SVG文件作为背景图片?
- 25. 如何为文本视图中的选定文本提供背景色
- 26. 淘汰赛绑定深层次背景
- 27. 如何为Kinetic JS舞台或图层添加背景颜色?
- 28. 如何使用相机视图作为背景只在内层
- 29. 如何将图像设置为图形的背景?
- 30. 如何重载CSS3的特定层分层多背景图片
只是''BackgroundColor'给'TextView'你的'梯度'。 – Ironman
查看我的回答 –