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"/>
Related
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"
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.
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 GridView which displays the user's photos. What I want to find is the exact columnWidth I have to specify so that the number of columns will vary from device to device, but always take up the entire screen (like QuickPic does). Right now my code is as follows:
//GridView inside Fragment layout file
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:horizontalSpacing="2.75dp"
android:verticalSpacing="2.75dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" />
//GridView row
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/ivPhoto"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitCenter" />
</RelativeLayout>
With my code, I get a lot of whitespace I don't want. I want it to have whitespace, but very little. I want the Grid to fill the entire screen with columns (photos), but leaving some little whitespace between them.
What would the perfect columnWidth be?
Thank you.
Making the Gridview adapt to different screen sizes is a little tricky using xml. A good solution is to adjust the size of the gridviews in your adapter's getView() method.
check out this example.
Adjust GridView to all Screen Sizes
I have the Views attached to each other in the following order:
Activity->RelativeLayout->RelativeLayout->Text
When I change the Y of one of the Text attached to the inner RelativeLayout, parts of it are cut.
Here's a screenshot:
http://s28.postimg.org/ypmvrjz25/image.png
I'm coding purely in Java, no XML.
What's going on?
It looks like one layout is overlapping on another because the menu bar is pushing it down. If you just want the text centered I would suggest setting that in the parameters like so.
android:gravity="center"
This places the text in the center if that is what you want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView12"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
As #Jonathan Whalen suggested you probably have some overlap, I suggest you to change your relative layouts background color to see wich one is overlapping the text. Also try to not use fixed height for the layouts but use wrap_content instead, as fixed dims are frequently the cause of layouts overlap.