[英]Android Rounded Corner Layout with Filled Tiled Image
我希望对此有一个xml解决方案...我试图创建一个具有圆角的布局,然后用图像填充该布局(平铺,重复)。 所以基本上我有一个LinearLayout,其中有一个分配给背景的可绘制层列表。 这是测试布局(xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/rate_buttons"
android:layout_width="100dp"
android:layout_height="50dp"
android:orientation="horizontal"
android:padding="0dp"
android:background="@drawable/test_rounded">
</LinearLayout>
</LinearLayout>
这是test_rounded可绘制xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item ><bitmap android:src="@drawable/my_tiled_image" android:tileMode="repeat"/></item>
<item >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="20dip"/>
</shape>
</item>
</layer-list>
图像在形状/布局边框的角处溢出。 我得到以下
如您所见,角落四溢。 我听说过要在代码中修改图像部分(蓝色图案),但是由于我确实对其进行了修改和动画处理,因此我对此有疑问。 所以,如果有可能仅用该图像填充布局,请告诉我。 谢谢大家的帮助。
您只能以编程方式执行此操作。 但是,如果要使用xml进行此操作,则必须在相对布局的帮助下将背景图像添加到圆角布局上方的布局中,并设置边距。 这不会提供完美的解决方案,但可以解决您的问题。
第一种是XML方式,在您各自的可绘制文件夹中为圆形边框创建xml文件。 我已将其命名为popupborder.xml。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke android:width="2dp" />
<corners android:radius="15dip" />
</shape>
The main layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/popupborder" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp" >
<LinearLayout
android:id="@+id/property_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner view with Background and margin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
我建议您使用图像加载器库,例如通用图像加载器,毕加索等。这是其示例代码:
String url = "file://" + your_file_path
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(url, ivPicture, options);
您必须添加
.displayer(new RoundedBitmapDisplayer(px))
到您的Universal Image Loader显示选项。
另外还有另一个库(我认为这是您正在寻找的) https://github.com/vinc3m1/RoundedImageView
您可以检查一下。 但是,以第二种方式,您可以获得加载大型图像的“内存不足异常”原因。
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.