Reputation: 67
I just want to create and display the example picture on top as a background in activity. Thanks in advance
Upvotes: 0
Views: 1351
Reputation: 237
there are many ways to design this layout
first set image as a background like this
android:background="@drawable/dummy"
Second create custom layout and used as a back ground like this
laout_custom_bg.xml (add in layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#fff"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8"
android:background="#2196F3"/>
</LinearLayout>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<include
layout="@layout/layout_custom_bg"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#FF9800"/>
</LinearLayout>
</FrameLayout>
Upvotes: 1
Reputation: 1
getWindow().setBackgroundDrawableResource(R.drawable.example);
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getWindow().setBackgroundDrawableResource(R.drawable.example);
}
Upvotes: 0
Reputation:
Use RelativeLayout, it's children can have elevations (heights on the z-axis). So you put the background picture to match parent (in width and height),and it's elevation 0.Then all other views have elevation >0.
Edit:you can also use Constraint Layout as in:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:elevation="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@yourpicturesource" />
<Button
android:id="@+id/button"
android:elevation="1dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
...other views
</android.support.constraint.ConstraintLayout>
Upvotes: 0
Reputation: 10887
There are many way to create the view.
I have used LinearLayout
here for the same.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=1
android:background="#FFFFFF"
/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=3
android:background="#0000FF"
/>
</LinearLayout
Upvotes: 0
Reputation: 34
Write on your xml : android:background=@drawable/imgname.extension
This must be on your
Upvotes: 1