I have a problem with the background of a View in this project.
There is one View with a transparent layer, which is not always displayed... It looks like if, in some cases, the height of this View was automatically set to 0, as I can see in the preview of the activity that contains the View. The code of this element is as follows:
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:alpha="0.5"
android:background="#drawable/background_layers" />
The main view group in this activity is a ScrollView. If the whole layout is displayed and is visible on the screen (so you don't need to scroll down) everything works fine (look at the transparent layer, which is the topic of this question):
But if the screen density is low, or if the device is in portrait orientation, and I must use the scroll because the full layout is not displayed at the same time... the previous View is not shown, the transparent layer is not visible :(
It happens when the app is running and also in Android Studio, in the preview screen, as I said. Here is an example with vertical orientation and low screen density, as seen on the preview tab of the activity in Android Studio:
Any idea to fix this isue?
Thanks in advance.
David.
I think I found the problem with your layout. The transparent_background view sometimes takes height 0 because its height is match_parent and its parent (the main_relative_layout view) has its height set as wrap_content. You should set the transparent_background dimensions relatively to another view, the LinearLayout that wraps the content maybe, using android:layout_alignTop, android:layout_alignBottom, android:layout_alignLeft and android:layout_alignRight attributes. You may need to remove the LinearLayout margin and use padding instead to align the transparent_background view correctly, let me know if you need some help.
Related
I wanted to implement a chessboard with gridlayout & framelayout. When I hardcoded the xml everything works fine. But when I tried to implement it programmatically all things fall apart. In xml I added
android:background="#color:blue"
to framelayout and it made a blue square but when I do this dynamically like
framelayout.addBackground(drawable)
no square shows up unless it has a child in it Broken chessboard
Also how to change the size of the chessboard square dynamically? It seems like gridlayout's grids don't get size from its parent rather from its child.
Any help is much appreciated. Take love.
I forgot to set height, width to the framelayout. That's why it was not showing anything. The potential solution is:
framelayout.setMinimumHeight(height);
framelayout.setMinimumWidth(width);
I have a list item that contains an image (red) and another layout (blue)
Normally, the layout would be the first one, but the black layout's width depends on user configurations, so it may not fit the whole content.
I thought about making it a Linear Layout and changing the orientation depending on its width, but i read somewhere its possible to do such things with layout only (maybe constraint layouts).
Is it possible to achieve this result using only "layout responsiveness", or do i have to input some code also?
I have an xml layout file for a venue details page, which specifies a few linear layouts and then a map view. Each linear layout has 2 TextViews, one as a header and another as the detail. At the bottom of the page is a mapView which shows the location of the venue.
On a large screen/tablet the map has plenty of room and looks fine, on a smaller screen, e.g. on a phone the map is squeezed into this tiny space at the bottom of the screen.
I'm happy with main layout of the page except for the map at the bottom.
What I would like to do is to specify that the minimum height of the map is at least the same dp as the available width - i.e. make sure its square. If there is more space for the map to fill at the bottom of the screen - i.e. to make it a portrait aspect rectangle, then it should do so.
Edit : I don't want to reduce the already dynamic size of the LinearLayouts as the information they provide is actually what the user will want to see.
pseudo code below:
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:minHeight="android:layout_width"
/>
I can see that it would be possible to do this through Java code. I can also see that I would be able to set a specific size such as 320dp, but this then requires more effort to get the size correct for multiple screen sizes.
Is this possible in xml alone?
Having had time to think about the comments made by #confused_at_times, I decided that in fact the problem was in the layout of my activity and not in the unavailable option in the xml.
My chosen solution is to have the map as the main element of the page with the marker pin being clickable and showing all available detail upon click.
It is not possible in XML for most View types.
As you know it can be accomplished in code, but I have always thought this type of a feature would be very helpful.
However for an ImageView you can accomplish something like this using the adjustViewBounds property, for example if you want a banner image at the top of your screen, and you want it to size correctly.
This XML below shows how to use that property:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="#drawable/big_image" />
First impression is that this image will match_parent in both height & width i.e. fill the screen. The scaleType will allow it to change size if required.
The trick is using adjustViewBounds set to true.
The image is scaled, but the bottom bound of the view is brought up to wrap_content of the newly scaled image.
Bear in mind that this method will not stretch a smaller image, but will work when shrinking a larger image onto a smaller screen.
I need to put a view (a image for example) in a custom point of the interface.
Are there a method to put a view in a exact pixel / virtual pixel (dp) - zone of the screen?
I need that the view is displayed above the other views.
I think to obligatory put a RelativeLayout and inside it all the layouts of the app and then put the view relative to this layout but i need a method more transparent to the future developers be able use it
EDIT:
I forget to say that i need to put the view programmatically and in the run time. I create the interface, make things in my app and then put a image in a concrete zone of the view above the others views for example in the half of the screen or in the top or in the 20% of the screen or ...
You can set margins for layouts and padding for views inside them, and you can specify position relative to edges, or to other views, there. Also you can specify fixed position for layouts by replacing (match_parent/fill_parent or wrap_content) with actual size( Note that you should specify all dimensions in dp or dip)
For instance you have a linear layout and you want an image view to be 20 dp to the right of the left margin you can try something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android::layout_marginLeft="20dp">
<!-- Nest your views here and if you want you can set padding for them
</LinearLayout>
If you want your views to be on a certain part of the screen, like top of the screen/ bottom of the screen etc, you can nest all of them inside a RelativeLayout. This is a nice way to do it, and it will remove any confusion.
Good luck,
Arkde
What about a FrameLayout as in the example I posted here?
You can use AbsoluteLayout, although it's deprecated.
The image is what i'm trying to achieve. I tried using tab layout, relativelayout and linearlayout (and even a combination), but in no scenario i got it exactly right.
The requirements:
no overlapping of any component
no clipping of the image in the button (the green one)
the red bar is always at the bottom
in landscape, the components should still be in their same place, but you can scroll down
If required I can paste my current variations of the different layouts, but they are all rather big and messy.
Professional insights on which layout approach you would use is also appreciated, at least i can keep trying using the right things then.
At the moment, the orange things are normal buttons, defined like so:
<Button
android:id="#+id/btn_web"
style="#style/NewButton2"
android:onClick="webClick"
android:text="#string/Text_Web"
android:drawableTop="#drawable/jc_menu_web"
android:layout_weight="0.3"
/>
This is a problem on its own,because if you stretch the buttons using fill_parent, the result is that the image will be high at the top, whereas the text will be entirely at the bottom.Would be nicer if it were a centered image in the button.