Listing different images along with text in android? - android

..i want to list different images..so

I dont fully understand your exact requirement. Anyways, you can use ListViews to make a list of images and textviews.
Assuming you want to have a ListView in which each row must contain an image and a text, you must define an xml inside /layout/ folder. Here is an example custom_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
/>
</LinearLayout>

Related

Problem In Recycler View Grid Layout Manager,

I have created a grid layout Like this:
But I want my grid layout some thing like this:
I want my text to be appear on right side. Like Contacts List. Please tell me what changes I must have to do in my layout file. Waiting for a good response.
Since you seem to want a list and not a grid, you should use a LinearLayoutManager, not a GridLayoutManager.
See the official documentation for examples.
Try changing the orientation of your linerlayout to horizontal.
this the xml code just copy and past
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/android_list_view_tutorial_with_example"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:padding="5dp"
android:src="#drawable/pic1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="YOUR TEXT"
android:id="#+id/album_title">
</TextView>
</LinearLayout>

listView and ScrollView

I have a linearlayout with 3 imageView and a listview in vertical orientation.i want to scroll the full screen including the images when the user scrolls the list.is that possible?thanks
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#222222"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph2" />
<ListView
android:id="#+id/ll4_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:cacheColorHint="#00000000" />
</ScrollView>
You definitely don't want to put the ListView inside of the ScrollView, but it's certainly possible to include the images. I would recommend considering putting the layout with the images in a header to the ListView. See addHeaderView. This related SO post may also be of use to you.
You should search api , the scrollView can not be inner more than one child , must has one direct child

Inflating a ListView with different number of ImageViews in each row

I'm starting to work with the Android LayoutInflater and I need some help.
I have a ListActivity which uses a layout defined in the following XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
This ListView is filled with an ArrayAdapter which generates each row by inflating another XML like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="20dip"
android:textColor="#FFF"
/>
<ImageView
android:id="#+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="6dip"
android:src="#drawable/example_icon"
/>
</LinearLayout>
</LinearLayout>
This is working fine, but now I want to show a variable number of icons for each item (so, each row of the ListView could have a different number of ImageViews under the TextView).
Maybe I have to define another XML for the list of icons and somehow build the ListView from nested layouts? I don't know what's the better way to do this. Any suggestions?
Thank you!
Edit: This is an example of what im trying to do: http://tinypic.com/r/2s9yniw/7
You'll just have to include a number of images in the XML layout for each row, and set the visibility of these to GONE when you no longer need them (you could put an image in one layout XML file and then include this 3 times on your row layout file).
You might be able to do it by inflating the image layout XML file as many times as you need for each row then adding it to the row view (but this gives problems with recycling if you only added 2 images the first time and the next row needs 3); but from what I remember you cannot add inflated content to an Adapter row or you get an exception (not entirely sure, so give it a try if in doubt).
In a particular row you can place the image views below the text view of that row and when you do not need to show them you can hide it by setting the visibility to GONE.

Crashes whenever I try to use a custom view object in XML layout

I have made myself a custom LinearLayout by the name of com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget that hosts a couple of spinner widgets. This custom LinearLayout inflates the following XML layout (You might not need to look at this too carefully but it's here for completeness):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Min value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_min_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1" />
<TextView
android:id="#+id/to_text"
android:text="to"
android:textSize="14sp"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_weight="0">
</TextView>
<!-- Max value Spinner -->
<Spinner
android:id="#+id/discrete_numerical_range_selector_max_value_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1" />
I have placed one such object in the layout for one of my activities like so:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include layout="#layout/search_form_section_generic_top"/>
<include layout="#layout/search_form_section_car_specific"/>
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
<include layout="#layout/search_form_section_advanced_options" />
</LinearLayout>
The problem is that my app force closes immediately upon startup. I've checked by putting breakpoints in my custom LinearLayout that none of my custom code is even being run yet. Furthermore, if I copy-paste the layout code for my compound widget in place everything works, which indicates to me that I probably haven't left any important XML attributes out. What could be going wrong?
I fixed it by making the LinearLayout XML element in the widget layout into a merge instead, and moved all of the layout parameters out of the widget XML file and into the activity XML itself, thus replacing
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget/>
with
<com.theflyingnerd.DroidMe.DiscreteNumericalRangeSelectorWidget
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
If someone could tell me why this worked, it might help me and others doing it again, and you can take credit.
because you must specify the width and height of every view you use in you xml?

What is wrong with this RelativeLayout?

I want to have three images in one row, and a Video or two below them.
So far, I am unable to correctly position the three images via Relative Layout.
It gets quite different behaviour from what I expect it to be... it shows only one picture, as though it is a FrameLayout.I can assure you the images are in place. And the java code is nothing but straightforward OnCreate - super.OnCreate, setContentView(R.layout.component_name) .
What is wrong with this relative layout?
<?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/previous_frame"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/previous_frame" />
<ImageView
android:id="#+id/catch_frame"
android:layout_toLeftOf="#+id/previous_frame"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/catch_frame"
/>
<ImageView
android:id="#+id/next_frame"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/next_frame"
android:layout_toLeftOf="#id/catch_frame"
/>
</RelativeLayout>
Check the code use android:toRightOf instead of android:toLeftOf..

Categories

Resources