There is a dialog with a lot of vector images. How to calculate the size of each picture for any screen?
If i use
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ava_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ava_item_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"/>
</FrameLayout>
i get this result
But i need automatically set size for imageviews. How?
In order to get all VectorDrawables of the same maximum size in Vertical Scrolling RecyclerView, you need to install in xml at the root element
android:layout_width="match_parent"
android:layout_height="wrap_content"
I suppose for horizontal scrolling the values of the parameters should be reversed.
Related
I would do put white space on top and on bottom of a recyclerView.
in html/css for example i can make a scrollable parent-container with fixed height and insert a child-container with adaptable height and set paddingTop and paddingBottom of child-container.
i tryed to repeat this system in layout.xml
<ScrollView
android:id="#+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="50dp"
android:paddingBottom="35dp"
android:clipChildren="false"
android:nestedScrollingEnabled="false"
tools:itemCount="10" />
</ScrollView>
but i see the "wrap_content" adapt height ONLY if that is minor of "match_parent", as the View is scrollable(in theory) (or that is what i undestand).
But this break my system because i need the child-container is NOT scrollable.
if i set nestedScrollingEnabled="false" cuts the elements out of the viewport, if i set "true" the recycleView scrolls normally but the whitespaces stay fixed
exist another way to get what I want?
attempted result
try to use this way by adding clipToPadding and set to false you can add white space in top and bottom
<android.support.v7.widget.RecyclerView
android:id="#+id/list_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/view_padding"
android:paddingRight="#dimen/view_padding"
android:clipToPadding="false"
android:paddingBottom="90dp"
android:paddingTop="90dp"/>
Open source code that I am using
in my design render it shows me the entire background is blue but the actually app only have color on the listviews. Following is my xml code and screen shots.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
render
actually app:
I tried to change the textview layout height to match_parent, but it still didn't work, so what do i need to do to change the entire background?
Thnaks
What's happening here is that your XML file is defining the layout for an individual element in that list view, then the list view is programatically applying this XML to build a new view onto the list whenever a new BLE device is discovered. The size of each list element is defined externally, by whatever is putting each of your views into the list. Therefore, when you put match_parent in the LinearLayout and expect that to fix your issue, it does not because it only fills the area allotted by the listview. The fix is to change the background color within the listview itself, which is not done in this XML.
I'd need to see to more code to know exactly how to do this, but I am going to take a shot in the dark and assume that you are using a ListActivity, as in the Google BluetoothLeGatt example. In this case, you can change the background color of the ListView using something like:
getListView().setBackgroundColor(Color.rgb(86, 159, 238));
Placed in the onCreate method.
The view indicated is only a view inside the layout that contains the ListView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b8569fee">
<TextView android:id="#+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b8569fee"
android:textSize="24dp"/>
<TextView
android:id="#+id/device_address"
android:layout_width="match_parent"
android:background="#b8569fee"
android:layout_height="wrap_content"
android:textSize="12dp" />
</LinearLayout>
You must change the background color to the layout that contains the ListView
android:background="#b8569fee"
Recently, designers in my company liked creating half-above elements in layouts for Android apps. I've been struggling for a while trying to make these elements behave as good as possible, but I'm already tired of it. Is there any way of positioning views like on this image
with an assumption that if user touch row/card it became "checked" and this black dot icon became visible (second click makes it invisible of course).
You can do something like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="#+id/circle_view"
android:background="#android:color/holo_blue_bright">
<android.support.v7.widget.CardView
android:id="#+id/second_view"
android:layout_width="100dp"
android:layout_height="match_parent"/>
</FrameLayout
<View
android:id="#+id/circle_view"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#android:color/holo_red_dark"
android:layout_marginEnd="-8dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
second_view is endOf circle_view so if circle_view is gone second_view will align to startOf parent.
circle_view should have marginEnd set to negative value of its width divided by two
I have a custom listview with ImageView and EditText , my problem is, with different image the size of imageview is different, like in photo.
How can I make sure that all images have the same size?
Image of listView
This is my XML code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="150px"
android:layout_height="150px"
android:adjustViewBounds="true"
android:layout_weight="0.1"
android:scaleType="fitXY"
android:layout_marginBottom="1dp"/>
To deal with different aspect ratio images your best approach is to choose a aspect ratio in your layout and center crop your images so they fill the available space.
<ImageView
android:layout_width="160dp"
android:layout_height="90dp"
android:scaleType="centerCrop" />
Well for better size, create linear layouts for each row containing an Imageview and Edittext.
You have set ScaleType to fitXY and that is good. Now use dp or fill_parent for Imageview size.
(Posted on behalf of the OP).
I have solved this - I have simply remove this android:layout_weight="0.1".
Just a quick question about how you would go about implementing this. I want there to be buttons at the bottom of the screen, but if the screen size is larger, more buttons would be added.
For example, at a small screen size, there might be 4-5 buttons at the bottom, but if you ran it on a tablet or something similar, there would be maybe 20 buttons.
Any suggestions? It can't scroll either, it just has to dynamically fill the layout with buttons.
Thanks.
To put buttons at the bottom of a layout, do something like this to your layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout">
<LinearLayout
android:layout_height="wrap_content"
android:id="#+id/button_layout"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:gravity="center">
<Button
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"></Button>
<Button
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"></Button>
<Button
android:id="#+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"></Button>
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_layout"
android:id="#+id/content">
<ListView
android:id="#+id/ListView01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ListView>
</FrameLayout>
</RelativeLayout>
To change how many buttons are shown based on the screen size, you should implement separate layouts for Multiple Screen Sizes..
http://developer.android.com/guide/practices/screens_support.html
Sounds like you want to create your own custom layout class. That or just fill a LinearLayout (for instance) until you run out of screen space.
If you know the size of your buttons in pixels you could use DisplayMetrics to get the dimensions of the screen then calculate how many buttons will fit in your allotted space.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.heightPixels givs absolute height in pixels
metrics.ydpi gives exact physical pixels per inch of the screen
and metrics.density gives logical density for scaling purposes
see here: http://developer.android.com/reference/android/util/DisplayMetrics.html
then just do something like
do{
Button button=new Button(context);
button.setText("yada yada")
button.allYoursettings....
.
.
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LinearLayout layout=(LinearLayout) findViewById(R.id.yourlayout);
layout.addView(button,p);
} while(havespaceleft);