i want to put multiple images and scroll down and see them all. I tried to put a ScrollView and inside a ImageView but i dont know if i need to put a layout. I searched tutorials but i didnt found what i needed.
That's clearly not how ScrollViews work. ScrollView is a ViewGroup, so you have to put it outside the view that you want to scroll.
Also, there can only be one view as the direct child of scroll view. So you cannot do this:
<ScrollView>
<ImageView>
<ImageView>
<ImageView>
</ScrollView>
Actually, you should put the images in a LinearLayout, and put the LinearLayout in the scroll view.
<ScrollView>
<LinearLayout>
<ImageView>
<ImageView>
<ImageView>
</LinearLayout>
</ScrollView>
Note: the attributes are omitted because I'm lazy :P
EDIT:
If you want to scroll down, just set the orientation attribute to "vertical".
<ScrollView>
<LinearLayout
android:orientation="vertical"
other attributes.../>
image views here...
</LinearLayout
</ScrollView>
Check out the Android documentation for CardViews http://developer.android.com/training/material/lists-cards.html
You can put an image within each CardView element and a sharebutton below the image. As I previously said, good memory management is a must when working with images and the RecyclerView will work just well.
Cheers
Try this method
<ScrollView>
<LinearLayout>
<ImageView>
<ImageView>
<ImageView>
<ImageView>
<ImageView>
</LinearLayout>
</ScrollView>
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>
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!
I have row_item.xml with nestem LinearLayout and multiple ImageViews. It generates 2 x 2 image grid in each row of ListView. On onClick aI want to know on which Image item user has clicked.
In onClick method I have tried to see which item is actually coming using item.getClass() and it shows LinearLayout. I am sure this will be top level layout in row Item. Here is my row item skeleton layout. I am looking for some generic approach where in I can get hold of clicked item at any depth.
<LinearLayout>
<LinearLayout>
<ImageView> </ImageView>
<ImageView> </ImageView>
</LinearLayout>
<LinearLayout>
<ImageView> </ImageView>
<ImageView> </ImageView>
</LinearLayout>
</LinearLayout>
You can set your image views clickable by setting appropriate options in xml where you declare your listView. And then just add onclickListeners to your imageViews.
For me solution that worked was setting:
clickable
focusable
focusableInTouchMode
to true. If you have this done, you can in your adapter getView/bindView setonClickListeners to your imageviews.
For each ImageView add the following:
android:clickable="true"
android:onClick="myOnClickFunction"
and add code like:
public void myOnClickFunction(final View imageView) {
// imageView.getId() - actual image view id.
}
I am new to layouts in android and would like to implement a layout like the one shown below however I am a bit confused as to how I should layer my layouts in XML.
I am currently trying a:
<LinearLayout>
<RelativeLayout>
<ImageView>
<TextView>
</RelativeLayout>
<LinearLayout>
<ImageView>
<TextView>
<ImageView>
<TextView>
</LinearLayout>
</LinearLayout>
I don't want to over complicate my layout structure. Would there be a better way to structure this?
Might be best to have a look at this link. As a rule of thumb, don't try and nest layouts too much, i.e. keep them as shallow as possible.
So relative layouts are usually better in this case.
http://developer.android.com/resources/articles/layout-tricks-efficiency.html
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.