I'm currently working on an app for 2 'players', the layout contains the same controls on top and (rotated) bottom.
I use an image as background to display it for both players:
Blue represents player one, red represents player two. Grey is for settings.
I used this until now, but I want the players to be able to change their background color.
My attempt was to put imageViews in the background, containing the selected color. But how can I put them in the background so my other views won't be affected? And how can I add multiple of them? I thought I could add two ImageViews to my RelativeLayout, the first one taking up 45% of parent space from top, and the second one from the bottom. The background itself would be grey for the center (for example).
How can I achieve that?
How about this?
<?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">
<LinearLayout
android:id="#+id/layout_center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:background="#android:color/darker_gray">
</LinearLayout>
<LinearLayout
android:id="#+id/layout_top"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layout_center"
android:background="#android:color/holo_red_light">
</LinearLayout>
<LinearLayout
android:id="#+id/layout_bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/layout_center"
android:background="#android:color/holo_blue_light">
</LinearLayout>
</RelativeLayout>
Related
I tried to do many things: set alpha value, set background:transparency, set backgroud different colors like "#90000000", I even created another view with transparency above my reciclerView. But I always have one result:
(do not look at white pictures, I will set them later)
And I need transparency like that one:
So as you see image and line are not under transparency. Do you have any ideas how fix it?
I think you declare the RecyclerView in the front of root,
if you are using a RelativeLayout like a main View in the xml layout, you have to make sur that your transparent View below your RecyclerView, this is an example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent">
</RecyclerView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9A000000">
</FrameLayout>
you can define two image view and first set the background your image and for secondly set the other background.but you must set the same size.
You can show a overlay above this recyclerview. Just like this.
<androidx.constraintlayout.widget.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"
tools:context=".MainActivity">
<RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000"
android:translationZ="100dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
LinearLayout works as overlay
Background image doesn't fill Linearlayout and changes that size
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#mipmap/dashboard_background"
android:orientation="vertical"
android:padding="10dp">
desirable look is this
How can I reach that?
You should use a frame layout with an imageview and a linearlayout inside
<FrameLayout
android:id="#+id/FrameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/background"/>
<LinearLayout
---Your Layout---
</LinearLayout>
Background always stretches to its View size. So you can't really control how it will look like. Instead, put an ImageView as a bottom most (meaning that it will lay under everything else) element in your layout, and use your background image as a source (src) for this ImageView, and so you will be able to control the look of the background with scaleType (probable you would want to use centerCrop or fitCenter). More about scaleType here.
In the end your layout should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#mipmap/dashboard_background" />
<FrameLayout
android:id="#+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put your view elements here -->
</FrameLayout>
</FrameLayout>
I Need to put two Images above my GLSurfaceView, each Image Needs to take 50% of the widt Hand 100% of the height (horizontal view). I am loading the Images from an api so I first get a base64 string of a png.
The GLSurfaceView Looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.kevingleason.androidrtc.de.kevingleason.androidrtc.VideoChatActivity">
<android.opengl.GLSurfaceView
android:id="#+id/gl_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
How can I "put" 2 Images on this view?
</RelativeLayout>
I have simple 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" >
<GridView
android:id="#+id/photo_browser_grid_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:stretchMode="none"
android:numColumns="auto_fit"
android:columnWidth="100dp">
</GridView>
I want to centre my GridView inside Relative layout. My spacing is always fixed. In result I have GridView aligned to left. How can I center it inside parent?
For GridView in the layout, android:numColumns="auto_fit" conflicts with android:layout_width="wrap_content". It means : to calculate how many columns to form, width is required, but to find width we need how many columns to wrap around, a circular dependency.
You can use android:stretchMode to let columns fill up empty space.
I have following code for main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layout"
android:gravity="center"
android:background="#00000000"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FFFFFF" />
</LinearLayout>
I need that the LinearLayout will be transparent. I thought that I can do it using the alpha setting in a background attibute, but it doesn't work. Please, tell me - I need that my application will be empty and has a white rectangle on the center of a screen.
You want the activity to be transparent?
Try using this theme in your activity tag (in the manifest file): #android:style/Theme.Translucent
For other possible ways, ie child theme see the following answers:
Activity should be transparent, but has black background
How do I create a transparent Activity on Android?
how to make activities transparent
Use below line in the xml file:
<Linearlayout android:background="#android:color/transparent"/>