I'm using this library to create a circular list. I want put items exactly in center of screen for all phones with different screen sizes.
How can i do that in a short way ?
We can use app:wheelRadius="350dp" to change radius of out circle ( wheel ). can i set a dynamic value for this to put elements in center of screen for all phones ?
XML
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.lukedeighton.wheelview.WheelView
android:id="#+id/wheelview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:repeatItems="true"
app:rotatableWheelDrawable="false"
app:selectionAngle="90.0"
app:wheelItemCount="14"
app:wheelItemRadius="25dp"
app:wheelOffsetY="100dp"
app:wheelPadding="13dp"
app:wheelPosition="bottom"
app:wheelRadius="350dp"/>
</RelativeLayout>
We have to parameter here. wheelOffsetY and wheelRadius that control wheel postition
Related
I notice that, the system attribute selectableItemBackgroundBorderless, is able to draw beyond view bound.
For instance, I have a 50x50 rectangle with background selectableItemBackgroundBorderless, I was able to get a visual circle pressed effect, which is larger than 50x50
Here's the 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">
<FrameLayout
android:clickable="true"
android:background="?selectableItemBackgroundBorderless"
android:layout_margin="50dp"
android:layout_width="50dp"
android:layout_height="50dp">
<LinearLayout
android:background="#ff0000"
android:layout_width="50dp"
android:layout_height="50dp" />
</FrameLayout>
</LinearLayout>
Here's the output.
I would like to achieve the same outcome, but with the following requirement.
It should follow the pressed view shape. If the view shape is 10x90 rectangle, then it should be a slightly larger 10x90 rectangle.
It should able to draw beyond the view boundary.
May I know how can I achieve so? - How to create a rectangle shape like selectableItemBackgroundBorderless, which is able to draw beyond view bound?
Thank you.
I have a RecyclerView with height:match_parent which displays 16 items vertically with fixed height in adapter. Everything works fine except when it comes to the different screen sizes. In larger screens there is a space remained at the bottom after 16 items are displayed, where on small screen phones it perfectly fits to the bottom. I am looking for a way where list items heights are adjusted to the RecyclerView height till the end without scrollable.
Check the Screenshots below for more clarification
Problem:
Expectation:
My approach was to make the Item weight set to 1, hence when rendering into the RecyclerView 16 times, they will share the same height within the RecyclerView. Unfortunately that didn't work for me.
My RecyclerView:
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_morning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
My Adapter:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white"
android:clickable="false"
android:orientation="vertical">
<TextView />
</LinearLayout>
The exact solution for your problem is the flexible layout manager for ReyclerView.
More about flexible layouts.
An example illustrating the use of flexible layouts.
I want to display an image as background in my app. Now I used this statement: android:background="#drawable/background" in <LineraLayout>. Here is the .xml Code:
<LinearLayout 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"
android:orientation="vertical"
tools:context="overbit.user.MainActivity"
android:background="#drawable/background">
</LinearLayout>
Now I get this output:
But I want it like this:
Maybe someone of you can help me. Thanks.
There is BitmapDrawable, which allows to do it. First you need to create a drawable resource as follows (let it be a file in the project resources res/drawable/mybg.xml ):
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background"
android:gravity="center" />
And then specify it as a background resource in your layout:
<LinearLayout 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"
android:orientation="vertical"
tools:context="overbit.user.MainActivity"
android:background="#drawable/mybg">
</LinearLayout>
You need to change the image's size itself in photoshop or something to achieve the desired result (still this can be very difficult because of various screen sizes of android smartphones). A workaround can be to change your parent layout to Relativelayout and then use a an imageview to show your picture like this:
<RelativeLayout 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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent" //make sure its match parent
android:layout_height="match_parent"// and this one also
android:src="#drawable/yourBackgroundImage"
android:scaleType="..."/>
<LinearLayout>put your childviews here</LinearLayout>
there are 4-5 options available for android:scaleType... experiment with them, till you get your desired result. Also note that you need to use android:src rather than android:background attribute of the imageview
You can accomplish what you're trying to do by using BitmapRegionDecoder.
From the docs:
BitmapRegionDecoder can be used to decode a rectangle region from an
image. BitmapRegionDecoder is particularly useful when an original
image is large and you only need parts of the image.
It allows you to decode a Rect area of a particular Bitmap fairly easily, the only thing you need to do is calculate your Rect region to decode relative to the Bitmap.
In android the position of an ImageView is determined by the top left side of the image. I am assuming that the x direction is 1/3rd of the width from the start point. Now we can set the pivot. Basically the location of the pivot point, is a location around which the view will rotate and scale.
int displacementX = ImageView.getWidth() / 3;
int displacementY = 10;
imgview.setPivotX((float)displacementX);
imgview.setPivotY((float)displacementY);
Now that we have set the pivot we can use a scale type to fit the image.
imgview.setScaleType(ImageView.ScaleType.CENTER_CROP);
I'm using a view with only 10dp height, so it just looks like a line.
If my layout_width is greater than a certain number (for example if I set layout_width=900dp), the view doesn't take the width... It seems that there is a max width for a view.
Does anyone know ?
Thanks.
Yan.
EDIT : Sorry, here's my xml layout.
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity" >
<View
android:background="#color/black"
android:layout_width="900dp"
android:layout_height="10dp"
android:transformPivotX="5dp"
android:rotation="45"/>
</RelativeLayout>
EDIT 2 : Here's the result. Why the view can't go further ?
http://image.noelshack.com/fichiers/2014/40/1411963572-screenshot-2014-09-28-22-36-32.png
It's because it's width and height are limited by the parents bounds, if you didn't rotate it you'll see that it just takes the parents width.
A View object's measured width and measured height values must respect
the constraints imposed by the View object's parents. This guarantees
that at the end of the measure pass, all parents accept all of their
children's measurements.
Source
If what you want is to draw a rotated line, you can consider doing so directly with a custom view. Follow this to get a head start
I'd like to display an image as a background for my activity, but would like to make it fill to screen without changing the aspect ratio of the image (something like this).
I tried scaling the image, but that doesn't seem to work (because I'm using the image as a background, not defining it in an imageview, or so seems the problem).
How do I go about doing that? I even tried to define the background image in its own xml file, but that still didn't work.
If you uses a RelativeLayout you can put a ImageView than fill all layout and put the rest over it. Something like that:
<?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" >
<ImageView
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/background" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
// Your full layout
</LinearLayout>
</RelativeLayout>
AFAIK the only solution is the one with ImageView you mentioned. Why it is not appropriate for you? You can also use Bitmap.createBitmap() method to resize your bitmap do desired size.