WearableListItemLayout: Remove item height limit - android

In Android Wear I'm using an WearableListView with WearableListView.Adapter to show items in a list. I have a custom layout for each item that has the parent WearableListItemLayout but it's problematic because the items are limited to approximately/exactly 80dp. I understand this is because of the "snapping" effect and follows the guidelines throughout the Android Wear system. My plan here is not to go outside of these guidelines more than a few dp's and I cannot make more sacrifices to the parts of the item (I have already chosen a too small font, too small icons etc..).
Item
<com.strafe.android.view.WearableListItemLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
android:paddingBottom="4dp"
android:paddingTop="4dp">
<!-- Textviews and other stuff -->
</RelativeLayout>
</com.strafe.android.view.WearableListItemLayout>
The code above cuts the item's TextViews and other parts of the item making it only 80dp high no matter if i have minHeight="100dp".
Is there any way to remove this limitation?

I think the device you are using has a screen of 240dp; the WearableListView is designed to work on Wearable devices in a way that each item takes exactly 1/3 of the screen height so in a 240dp display, each item will be 80dp and you cannot change that.

Related

How to make an initial screen to fit every mobile screen or support multiscreens

I am working on an android project. My first screen consists of one imageview and three textviews everything is clearly visible when the mobile positioned vertically if the mobile positioned horizontally then some text views are not visible how to make my app which fits to screen and supports all positions(vertical/horizontal).
Thank you.
You need to add a ScrollView to your layout. As in landscape the screen height is decreased, so lesser area is left to show elements.
ScrollView will manage all the things for you. If space available is less than required then Scroll bar will be shown otherwise not.
If you are sure that it will fit on any screen size, consider using RelativeLayout, with this you can say where it needs to align on the screen at all times. Of course if it can overflow than using a Scrollview is a much safer option.
You can use a scrollview to fit the screen in length, or you can use PercentRelativeLayout.
How to use a scrollview:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<--yourcodehere-->
</TableLayout>
</ScrollView>
Add this to your gradle to use PercentRelativeLayout:
compile 'com.android.support:percent:23.2.0'
Then you can use it like this:
<Button
android:text="#string/Tesksten"
android:id="#+id/btContent"
android:layout_below="#+id/searchView"
android:drawableTop="#drawable/ic_menu"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_heightPercent="16%"
app:layout_widthPercent="100%"
android:padding="10dp"
android:textColor="#000000"
android:background="#f0f0f0"
android:textStyle="bold"
android:alpha="0.65"
android:layout_marginBottom="10dp"/>
This is how this button looks now, note that there are more lines to get MY specific layout, remove if needed. Make sure you put Width And height to 0 and then use Percent, i had some problems figuring it out at first to. Goodluck.:
Or if you want to fully turn off screen rotation, add this to your manifest activity, that you dont want to rotate:
android:screenOrientation="portrait"

In Listview one row in bigger in size

In my listview one row was in bigger in size.
Initially all are in same width and height
After scrolling some time one row become bigger (see in below image)
now in Entertainment
Scrolling again that Gaming will become bigger
How to resolve?
It looks like your items are varying in height a little bit.
One of the standard things to do for a ListView is to use the Android Attribute listPreferredItemHeight which will provide a preferred item height for the device.
So. Your layout for the list items would look something like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
/>
This will give you a single TextView for each item, with the preferred system height.

ActionBar overlay with GridView padding or custom GridView to show entire first image?

I have an activity with a GridView inside it. The ActionBar is set to overlay mode.
Right now, you can only see half of the first image because the ActionBar cuts it in half.
How do I add padding to the interior of the GridView so that it initializes in such a way that you can see the entire first image? Or is there another way? For example, how would I go about extending GridView to create one that has a built-in configurable, dynamic gap at the front?
example (although ListView instead of GridView): reddit is fun app: https://play.google.com/store/apps/details?id=com.andrewshu.android.reddit
edit: I'm hiding the ActionBar whenever the user scrolls down at a certain rate or past a certain level.
Use a ViewTreeObserver.OnGlobalLayoutListener in your Activity or Fragment to determine the number of columns your GridView will display (presuming it varies based on screen size and orientation), then use that number in your Adapter implementation. In getView(), if position is less than the number of columns, return an empty view whose height matches the Action Bar, otherwise bind your data as you would normally.
There is an excellent example that does exactly what you want in Google's "Displaying Bitmaps Efficiently" sample application: https://developer.android.com/training/displaying-bitmaps/display-bitmap.html
Here is the relevant source code:
https://android.googlesource.com/platform/development/+/master/samples/training/bitmapfun/src/com/example/android/bitmapfun/ui/ImageGridFragment.java
Try adding android:layout_marginTop="?android:attr/actionBarSize" to the parent of your GridView, or the GridView itself if it doesn't have one.
This will push your layout down so that it rests below the ActionBar.
Edit
You may want to conside using a ListView instead of a GridView. Reason being, you can easily achieve that effect by creating a fake header and then calling ListView.addHeaderView. You can't do the same with a GridView. What you're talking about can definitely be done with a GridView, but it will require you to subclass it and modify it quite a bit.
Header
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize" />
Having ActionBar in overlay mode, the following works for me:
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
android:clipToPadding="false"
android:numColumns="auto_fit"
android:columnWidth="120dp"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:id="#+id/gridLibrary" />
The most important lines here are: android:paddingTop and android:clipToPadding.
In my application, when I open an activity with the gridview above, the first row is fully visible. Then, when I scroll down, the ActionBar hides and the gridview fills up all the screen.

android listview doesn't stick on the top of the layout

I have this xml file. The list contains 2 items. When I test the application on the SDK emulator or a tablet, it is displayed as intented. However, when I download the application on a Samsung GT-S5570 with Android v2.2.1, the user can drag the list from the top and move it towards the bottom of the screen. Is there any way to prevent this from happening?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="20dip"
android:id="#android:id/list"
android:cacheColorHint="#android:color/transparent"
android:textAppearance="?android:attr/textAppearance"/>
</RelativeLayout>
If you just want to display limited number of items, then put that items within the ScrollView instead of using ListView.
ListView is intended to display unlimited number of items with scrollview to scroll other items.
This answer is the more informative and helpful: how can i automatically size listview so it doesn't scroll

List items don't highlight uniformly when tapped

What would cause only a portion of a list view item to highlight when tapped?
I'm working on an Android app where the user navigates through a series of lists, and some of the list items don't highlight properly. The list items have an image on the left followed by text. If the text in the item mostly fills the row, the entire row highlights when tapped. If the text is short, however, then only part of the row highlights when tapped. I'd really like the entire row to highlight regardless of the length of the text. My list item layout looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="#+id/zoneIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="5dp">
</ImageView>
<TextView
android:id="#+id/itemtitle"
android:layout_width="fill_parent"
android:textColor="#color/listItemColor"
android:textSize="14sp"
android:layout_gravity="top|left"
android:layout_height="fill_parent"
android:padding="13dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
I thought that setting the layout_width of the text view to fill_parent would cause the text view to fill the remainder of the item's width, and that the whole row should highlight. Is there something else I need to set to control the width of the overall item? What am I doing wrong?
Edit: I also have another problem which may be related: When I scroll the list (which normally has a white background), the area occupied by the list items turns black during the scrolling, and then appears normal again when scrolling stops. The black area is the same size as the area that would be highlighted (except that it's all the items rather than just one), which is to say that there are white spaces on the right side of some of the items while scrolling. I'd like to prevent the list from turning black while scrolling, but perhaps that's another question. I mention it because it makes me think that some list items aren't filling their parent, but I'm still not sure why.
The black background is controlled by android:cacheColorHint (XML) or ListView.setCacheColorHint (Java) -- it used for drawing a solid color underneath the list while scrolling for performance reasons.
The list item should highlight in full regardless of the size of the TextView since the LinearLayout fills the parent. However you should certainly change the height of the LinearLayout towrap_content` -- it doesn't make much sense for it to fill a parent since the height of a list (and therefore the maximum size of a list item) is unbounded.
The height of the TextView and ImageView should probably be set to wrap_content as well. See if those changes resolve your issue.

Categories

Resources