如何将垂直平铺(仅)背景添加到Android应用程序
在Android应用程序中,水平和垂直重复线性布局的背景非常简单。您只需使用tileMode(请参阅) 然而,xml文件中的tileMode不允许我仅在垂直轴上重复背景图像。有一个tileModeY,但不能从xml访问它 我正在尝试将该属性修改为“repeat” 我有一个带有线性布局的main.xml文件:如何将垂直平铺(仅)背景添加到Android应用程序,android,eclipse,layout,background,Android,Eclipse,Layout,Background,在Android应用程序中,水平和垂直重复线性布局的背景非常简单。您只需使用tileMode(请参阅) 然而,xml文件中的tileMode不允许我仅在垂直轴上重复背景图像。有一个tileModeY,但不能从xml访问它 我正在尝试将该属性修改为“repeat” 我有一个带有线性布局的main.xml文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andr
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainMenuLayout"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
但我的背景仍然是黑色的。当然,我可以从xml中添加它,但它在x轴和y轴上都会重复
所以我的问题很简单:如何在我的活动中垂直重复“welcomebackground”图像?我找到了解决方案:可能重复
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/welcomebackground"
android:dither="true" />
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
BitmapDrawable background = (BitmapDrawable) res.getDrawable(R.drawable.welcomebackground);
background.setTileModeY(Shader.TileMode.REPEAT);
(new View(this)).setBackgroundResource(R.drawable.welcomebackground);
}