I'm trying to create an app. I have 4 TextViews, and 4 ImageViews. If I want to put something else at the top of the layout, I have to move all 4 TextViews and all 4 ImageViews down, but I don't want to move them each separately (it takes more time). I`m thinking if there is any possibility to put all of them in a List or something like this, and move all of them only by one xml code.
For example
<TextView/>
<ImageView/>
<TextView/>
<ImageView/>
<TextView/>
<ImageView/>
and move down all of them by one code to make free space for another TextView and ImageView.
Are they all stacked up like that? Try putting them in a LinearLayout, then set attribute layout_marginTop to how much you want them to go down.
Related
I'm new at Android programming and couldn't solve how to do a design problem.
I have an activity with constraint layout, and it is full of textviews and buttons.
I want to put 6 imageview tool top of to the this activity. And there should be 3 of them should be seen on the screen, other ones should be scrolls to the right side. Like the screenshot I'm uploading.
Only these 6 imageviews should be scrolling horizontally.
I don't know what to do, which tools should I use. How can I do that design?
Thanks.
For the 6 ImageViews scrolling horizontally, I would advise you make use of a RecyclerView which is very powerful in dealing with showing data in a list especially for very large data sets. You can check out how to work with a RecyclerView here.
Since you only have 6 ImageViews, you can make use of a HorizontalScrollView, a LinearLayout with orientation set to horizontal i.e android:orientation="horizontal" and then place your ImageViews inside the LinearLayout.
<HorizontalScrollView ...........>
<LinearLayout ......>
<ImageView......./>
<ImageView......./>
<ImageView......./>
<ImageView......./>
<ImageView......./>
<ImageView......./>
</LinearLayout>
</HorizontalScrollView>
The easiest solution here is a HorizontalScrollView.
As HorizontalScrollView only accepts one child, wrap your ImageViews in another layout, e.g. LinearLayout or ConstraintLayout, then put that in a HorizontalScrollView.
You can use horizontal recyclerview for imageviews and below horizontal recyclerview, you can use linear layout for textviews inside scroll view.
<ScrollView>
<LinearLayout>
<RecyclerView>
</RecyclerView>
<LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
The best I could explain this is by the image above. I have 4 views(1,2,3,4) which are linear and relative layouts and I have 5 which is a linear layout inside of 1, but 5 has to overlap 2.
If I contain 1,2,3,4 inside a linear layout I can arrange them but 5 wouldn't then be able to overlap 2 it would be cut off by it, I tried view5.bringToFront(); view5.invalidate(); but it didn't work.
So I guess 1,2,3,4 must be contained within a framelayout, but how then would I be able to align them vertically the way a linearlayout would do(1 then 2 then 3 then 4 above each other like the image provided)
Or is there a better way to do this?
It's simple hierarchy in this case. The view that is written first will be drawn first. SO if you want your 5th view to come on top of your linear layout make your xml like this
<FrameLayout
.........
.........
<LinearLayout
............
............
/>
<View
......5th view...
.................
/>
</FrameLayout>
I am developing an app on Android with this form :
<ScrollView>
<RelativeLayout>
<TextView/>
<RelativeLayout>
....
</RelativeLayout>
<gridLayout>
7 CheckBoxes
1 ImageButton
</gridLayout>
<LinearLayout>
many TextViews
</LinearLayout>
</RelativeLayout>
</ScrollView>
The ImageButton inside the gridLayout controls when some of the checkBoxes disappear (VISIBILITY->GONE) and when it's pressed (the ImageButton) the LinearLayout, which is just below it (the gridLayout), overlaps the gridLayout before it takes its final form. See the images below :
[1]: https://i.stack.imgur.com/K6aSc.png This is before the disappearance.
[2]: https://i.stack.imgur.com/nHqpj.png This happens during the disappearance.
EDIT: The problem happens because the View.GONEtakes some time to be performed visually, but the gridLayoutunderstands that it happens immediately, so it reserves the "empty" space right away. Only think I can figure out, is to set the View.INVISIBLE instead and resize the gridLayout manually. Is there a better way?
EDIT2 The problem is caused by animateLayoutChanges="true". Due to the animations, it take some time for the checkBoxes to disappear. Is there a way to force the linearLayout to "wait" for the effect of the animation to end?
Any ideas?
You can add a listener to your animation changes of animateLayoutChanges="true" and move the LinearLayout when the animation ends. More information in this thread - Listner
Also, you can try a combination of setAlpha(0) and setEnabled(false) on your checkboxes in which case gridLayout won't adjust the views again.
I'm pretty new to Android so sorry if this is obvious.
I currently have a few cards that I would like to display extra information when clicked. At the moment they have 6 lines of text and a couple of pictures. I want to display one line of text when the card is pressed and go back when it is pressed again.
The plan I have at the moment is to have 2 identical in size cards and set the visibility of one to gone and when the other is clicked set it to gone and make the other one visible. Is this the best way of doing this? For example, I could use one card and just swap the content.
Thanks for any advice in advance
edit - I'd also like to add some kind of transition - maybe a fade between them so ideally this would be possible too
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout>
<ImageView/>
<TextView/>
<TextView/>
<TextView/>
<ImageView/>
<TextView/>
</LinearLayout>
</android.support.v7.widget.CardView>
Replace with
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<TextView/>
</android.support.v7.widget.CardView>
where the text view is different. I'm basically asking if I should make an entirely new card of just hide all the other text/imageviews and show the new one. I hope I've explained a bit better
I have three linear sub layouts in my activity window in my Android application. Each layout has one scroll bar. My problem is when I am trying scroll in one layout area other layouts scroll bars also activating. Could you please suggest a solution for this?
ONE <scrollView> can hold at max ONE component inside it....... this ONE component can be either a layout holding several other views or further layouts inside it, or it can be a single view.
in order to have 3 separate scrolling linear layouts (meaning scrolling one linearLayout does not affect other LinearLayouts)..... you should have 3 separate <ScrollView> elements - each scrollview containing at max ONE of your THREE linearLayout.
for example:
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout1** goes here
<LinearLayout>
</ScrollView>
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout2** goes here
<LinearLayout>
</ScrollView>
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout3** goes here
<LinearLayout>
</ScrollView>
hope it helps you.