To prevent from re-posting all my code again, it can be found in this question.
What I'd like to do now, is to prevent the upper imageview from shrinking upon scrolling; instead, I'd like to make it 'static' so it won't scroll up and shrink when the lower view is scrolled over it.
I'll add some pictures to compensate for the loss of clarification.
This is how the screen looks at it's fullest size:
This is how it looks when it's shrinked:
This is what I want:
Edit:
Forgot to mention what I tried and didn't work. Tried playing with the collapseMode of the ImageView which appears not related.
Also tried playing with the scrollFlags attribute of the CollapsingToolbarLayout, removing flags and adding enterAlways, but none worked. I have no clue on how to achieve this effect.
This simplest way would be to set the parallax multiplier to 1:
<ImageView
android:id="#+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1" />
Related
I am working on an android application and it was agreed to only have 3 fragments in its bottom navigation bar. However, things have expanded and we decided to add another fragment. When adding the 4th fragment, the dimensions of the container break making it look like this.
This is my xml code.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#drawable/selector"
app:itemTextColor="#drawable/selector"
app:menu="#menu/menu_navigation" />
I have tried different properties to make it stretch but they end up putting it only to the right and not expanding left or vice versa. For instance if I was to try using wrap_content on the layout_width, the container would glue itself to the left.
What is the needed property that might be a solution to the problem?
It's an automatic measure in order to not have labels overlap.
You can make a quick fix by adding app:labelVisibilityMode="labeled" to your xml.
Note that you should use Use Support Library 28 for this.
I'm pretty new to android and wanted to ask about the centering practices, what I mean is that for example:
Before I say something, I don't know what are the good practices are so...
I can have a LinearLayout with height as match_parent and android:layout_marginTop="?attr/actionBarSize"(btw, according to google's material 56dp).
So that is one option, but, I saw apps where the content is centered nicely if the device is really long(such as Galaxy Note devices), so what I did is:
Same LinearLayout but with height as wrap_content and android:layout_gravity="center", but the problem here is with for example a form with 1 field(almost no content height), the problem is that almost no content will leave you with a lot of space between the toolbar and the content and below that content as well.
My question: altought may be obscure I'm asking for the best practices, what is the best approach that will make content(bigger or smaller) appear nicly on multiple devices, maybe it would require multiple layouts/dimens, I'm ok with that, just looking for the right path.
There is another view group named RelativeLayout.
You can use it like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
// here you can use attributes such as `android:layout_below`, `android:layout_above`,`layout_toRightOf`
//to modify and control your items
/>
</RelativeLayout>
I have a problem with a fixed size scrollview that i'm trying to make. I've read many questions that are similar (but not equal) to mine here in StackOverflow and other sites and none of the answers have helped me, so I decided to ask my own question.
Basically, i want a fixed size scrollview with different controls inside. The basic one would be a textview of a dynamically changing size inside it. When I change the text of the textview and it is bigger than the scrollview, the scrollbars flash quickly, as they should, indicating that I can scroll but no matter how many times I swipe my finger, it doesn't scroll. Then I tried swiping with two or three fingers and sometimes (only a counted number of times) it scrolls.
I have tried many different approaches to this, like changing the textview to an edittext with focusable = false so it doesn't give the user chance to edit the text; or putting the textview alone in the scrollview, or wrapping it in linearlayouts, relative layouts etc. and it still doesnt scroll.
Below is the code as it is today. This scrollview is inside a vertical linearlayout along with other controls that I'm not putting 'cause of the length, but if someone needs it, I'll put it. I would appreciate very much if someone can point to my problem or help me solving this.
XML:
<ScrollView
android:id="#+id/scrollFifthHorizontalLineDetails"
android:layout_width="304dp"
android:layout_height="133dp"
android:layout_gravity="center"
android:layout_marginTop="5dp" >
<LinearLayout
android:id="#+id/rrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtlblPlaceDetails"
android:layout_width="302dp"
android:layout_height="wrap_content"
android:background="#drawable/placedescriptionbg"
android:text="#string/null_text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
the line in which I populate the TextView:
((TextView) findViewById(R.id.txtlblPlaceDetails)).setText(mJsonOb.getString("placeDescription"));
I had a similar problem with an Android app I was developing a few months back. I got around the scrolling problem by increasing the layout width for the scroll view. In the editor you can actually drag the RHS of the scroll view to exceed the visible area. I think I set the android:layout_width to about 1024.
I'm designing an app with many images, buttons and textViews strewn across the screen. At the moment I am using the relative layout as it seemed the most flexible of the lot. However were I place my elements and their size is still restricted to being aligned with other elements. Even worse if an element changes size any elements aligned to it will also change size.
There must be a simple solution to this! Apple's nib files perform this so easily with an effortless drag and drop to any location; yet android appears to be stuck with restrictive table/linear/relative/grid layouts.
If possible can the solution be performed via eclipse. If not please guide me to the relevant documentation to learn to create my own layouts via xml, create a huge grid layout or whatever horrors await me :)
Thanks
I think what you want is something like an absolute layout tho these were deprecated a while ago, Im pretty sure you can still do this via a Relative layout, you don't necessarily need to align the via with another view, I guess you could just do something like 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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="70dp"
android:layout_marginTop="82dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="172dp"
android:layout_marginRight="84dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
all I'm doing here is aligning it with the side of the parent and having a margin between it
You can do what you ask with a Frame Layout and setting the position of each object. But do so at your own risk. The reason Apple nib files let you arbitrarily place objects is taht the aspect ratio of all their devices is the same. So your layouts just scale up and down evenly.
Android is a more diverse ecosystem, and you should try to embrace layouts that adapt to different screen sizes and orientations.
Take a look at Android custom layout and Android - How to draw a letter at a specific point?
Are you planning to only use the app on a single android device model? If yes, check AbsoluteLayout's Alternatives. (FrameLayout or RelativeLayout)
It's not a good idea to put "Anything Anywhere you want" since Android devices have a lot of different screen sizes and properties. The only option would be to define your own custom layout.
I actually really like the way Android tries to make your layout compatible with as much devices as it can using alignment and structured layout views.
The reason it's simple for Apple is that you're only targeting iPhone, which has a fixed screen properties accross all devices.
Hope it helps. Good luck.
I'm writing an application for Android phones for Human vs. Human chess play over the internet. I was looking at some tutorials, to learn how to develop Android applications and found a very nice example of making galleries (it was a GridView usage example for making a gallery about dogs) and the idea came to draw the chess table using a GridView, because the example project also handled the point & click event and I intended to use the same event in the same way, but for a different purpose. The game works well (currently it's a hotseat version), however, I'm really frustrated by the fact that whenever I rotate the screen of the phone, my GridView gets hysterical and puts some empty space in my chess table between the columns. I realized that the cause of this is that the GridView's width is the same as its parent's and the GridView tries to fill its parent in with, but there should (and probably is) be a simple solution to get rid of this problem. However, after a full day of researching, I haven't found any clue to help me to make a perfect drawing about my chess table without a negative side effect in functionality.
The chess table looks fine if the phone is in Portrait mode, but in Landscape mode it's far from nice.
This is how I can decide whether we are in Portrait or Landscape mode:
((((MainActivity)mContext).getWindow().getWindowManager().getDefaultDisplay().getWidth()) < ((MainActivity)mContext).getWindow().getWindowManager().getDefaultDisplay().getHeight())
In the main.xml file the GridView is defined in the following way:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="8"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
...
</LinearLayout>
I appreciate any help with the problem and thank you for reading this.
Portrait: http://www.freeimagehosting.net/image.php?f388b3ec64.png
Landscape: http://www.freeimagehosting.net/image.php?ee790603a2.png
A GridView probably isn't what you want here. GridView, like ListView, is for efficiently presenting scrolling, unbounded data sets. A chess board is neither. Populating a TableLayout programmatically is probably what you want instead.
The reason your GridLayout doesn't seem to be honoring android:layout_width="wrap_content" is that since GridView is meant for displaying unbounded data where each item can have a different size, it doesn't trust that items have a uniform width that can be reasonably measured. (If an adapter has 10,000 items, should GridView measure all of them to determine the correct column width?)
If you're going to try to keep using GridView for this anyway (which you shouldn't), try setting an explicit value for android:layout_width rather than wrap_content. This will stop the GridView from expanding to fill the available space. You can also use alternate layouts for different screen orientations using the resource system as described here. Alternatively you can disable landscape mode using android:screenOrientation="portrait" on the activity tag in your manifest. ;)
The problem is simply solvable using the setPadding method of your GridView object.