我需要在imageview的左侧放置一条橙色线。我投入了“艰难的道路”并且有效:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp" >
<LinearLayout
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="#FF7F24" >
</LinearLayout>
<ImageView
android:id="@+id/image1"
android:layout_width="50dp"
android:layout_height="60dp"
/>
</LinearLayout>
有一种方法可以直接使用图像中的可绘制xml文件而不使用线性布局来实现此效果吗?
感谢您的帮助!
答案 0 :(得分:2)
使用以下代码作为imageview的drawable
<item>
<shape android:shape="rectangle" >
<solid android:color="#FF7F24" />
</shape>
</item>
<item android:left="5dp">
<bitmap android:shape="rectangle"
android:src="@drawable/image"/>
</item>
答案 1 :(得分:0)
您始终可以创建shape并将其设置为LinearLayout的背景而不是“#FF7F24”。 但由于你只想要一个纯色,我认为你实现它的方式很好