How to design 2 different layers in one activity - android

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>

Related

arranging views in framelayout

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>

Most fitting View/Layout for placing several text- and image views inside, XML for Android

So I have this ScrollView inside which I have a RelativeLayout on one of my views on my Android app. Inside the RelativeLayout I already have a TableLayout that I'm using, and above it I want; 2 different text views (one header and one longer text, and I want the header to be placed on top of the longer bit of text) aswell as an ImageView that I want to be placed to the right of the 2 TextViews, and I want all 3 views to be placed on a differently colored background than the other stuff on the ScrollView such as the TableLayout for example.
I tried putting another RelativeLayout inside the ScrollView but it tells me ScrollView can only host one direct child, so that didn't really pan out. What would the most fitting way to accomplish this? Because I want this 3-view-background-thingie to scroll with the TableLayout and all the other stuff on the view.
As always, thankful for any answers or tips!
(My design kinda looks like this at the moment, schematically;)
<Container (that doesn't scroll)/>
<ScrollView
<RelativeLayout
*Alot of stuff here, such as a TableLayout for example
</RelativeLayout>
</ScrollView>
Put everything in your RelativeLayout
<ScrollView
<RelativeLayout
<LinearLayout>
<TextView>
</TextView>
<TextView>
</TextView>
<ImageView>
</ImageView>
</LinearLayout>
<TableLayout>
</TableLayout>
</RelativeLayout>
</ScrollView>
This way, the only child is the RelativeLayout, the others being children of the RelativeLayout.
Hope this helps!

listView inside of a linear layout with something else

i was just wondering if it was possible to have in one layout xml file, maybe a vertical linear layout at the top have a horizontal linearLayout and then below that (inside of the vertical layout) have a list view that takes up the rest of the screen?
I couldnt find any information specifically on this, and i'd like to know if its possible before i attempt it, thanks!
Give the ListView layout_height="0dp" and layout_weight="1". It will take up the remaining space not used buy the sibling LinearLayout.
<LinearLayout
android:layout_width:match_parent
android:layout_height:match_parent
android:orientation:vertical >
<LinearLayout
android:layout_width:match_parent
android:layout_height:wrap_content
android:orientation:norizontal >
<!-- other views --->
</LinearLayout>
<ListView
android:layout_width:match_parent
android:layout_height:0dp
android:layout_weight:1 />
</LinearLayout>

ListView inside two LinearLayout and scrolling issue

I have this structure
<LinearLayout
android:id="#+id/1">
<LinearLayout
android:id="#+id/2" />
<LinearLayout
android:id="#+id/3">
<ListView
android:id="#android:id/list" />
</LinearLayout>
</LinearLayout>
And I populate the ListView with some data. Well my problem is that the ListView becomes scrollable (while the LinearLayout number 1 fits the screen without scrolling), but what I want is this View to become full height and that the LinearLayout with id=1 becomes scrollable.
Inside ListView number 2 I have some TextViews, etc.
ListView's are scrollable by default if when the content is more than its display area.
However, LinearLayout would need to have a ScrollView in order to scroll.
Red Alert - You cannot use ScrollView and ListView together. You will end up seeing un-expected.
Alternate Solution: Prioritize what is more important to you, if scrolling the entire screen then add a ScrollView (provided your ListView items are static) else I will to wait to hear a good solution on this one. :)
Add ScrollView for ListView.
ScrollView will work for only one child view, so you have to add like this
LinearLayout
LinearLayout
LinearLayout
ScrollView
ListView...../ListView
/ScrollView
/LinearLayout

How to float/overlap a view in android?

I have many activities with a scrollview inside a tablelayout. However, it is necessary a small design change, so I have to put a black transparent view over the whole screen from the top to the bottom. Is it possible to do it in the tablelayout or the scrollview?
RelativeLayout allows for easy overlapping of views. You'll have to adjust the existing views in your app because it doesn't do anything automatically.
EDIT:
A quick way to do this would be to take your existing view (the ScrollView) that is already organized and put it in a top-level RelativeLayout. Then, all you have to do is add new view inside the RelativeLayout with the width and height both set to MATCH_PARENT. The result should be the black transparent view will be visible over the ScrollView.
I normally use FrameLayout to achieve any kind of 'layering' of views.
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
//your existing layout
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#33000000" />
</FrameLayout>
As DeeV said, you can probably use RelativeLayout in a similar way, but you might have to set additional attributes on its children to achieve this.

Categories

Resources