我希望有一个 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>
关于java - Android 圆角布局与填充平铺图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26367986/