У меня есть вопрос, я хочу, чтобы в моем приложении было статическое фоновое изображение.Изображение находится в папке res / drawable проекта.
На просмотр списка и другие компоненты не должно повлиять.
Как я могу это сделать?Thx
Пожалуйста, смотрите мой код ниже:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="@+id/kpn"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
<Button
android:id="@+id/btn_login"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/txt_username"
android:layout_marginLeft="2dp"
android:layout_marginTop="3dp"
android:layout_x="2dp"
android:layout_y="270dp"
android:text="Login" />
<EditText
android:id="@+id/txt_username"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/kpn"
android:layout_marginLeft="1dp"
android:layout_marginTop="30dp"
android:layout_x="1dp"
android:layout_y="220dp" />
<Button
android:id="@+id/cancel_button"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txt_password"
android:layout_alignTop="@+id/btn_login"
android:layout_x="120dp"
android:layout_y="270dp"
android:text="Cancel" />
<EditText
android:id="@+id/txt_password"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/txt_username"
android:layout_marginLeft="177dp"
android:layout_x="120dp"
android:layout_y="220dp"
android:inputType="textPassword" />
</RelativeLayout>
Edit:
Я решил это, установив следующий код в onCreate (...) моей деятельности, какитак:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Set background image
View view = getWindow().getDecorView();
int orientation = getResources().getConfiguration().orientation;
if (Configuration.ORIENTATION_LANDSCAPE == orientation) {
view.setBackgroundResource (R.drawable.yourepicture);
} else {
view.setBackgroundResource (R.drawable.yourepicture);
}
Спасибо за подсказку Мистера Сквонка ..