I created app to display images from internet in carousel view. I loaded images into carousel view using imageview. just like following way.
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.showsmain, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
// RelativeLayout rlayout=(RelativeLayout)vi.findViewById(R.id.rlayouts);
image.setImageResource(R.drawable.black);
orgWidth = image.getDrawable().getIntrinsicWidth();
orgHeight = image.getDrawable().getIntrinsicHeight();
imageLoader.DisplayImage(data[position], image);
imageLoader.getDimension(widthScreen, heightScreen);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
widthScreen, heightScreen/3);
params.width=widthScreen;
image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.FIT_XY);
//rlayout.addView(image);
return vi;
}
and my carousel layout xml file is,
<com.touchmenotapps.carousel.simple.HorizontalCarouselLayout
android:id="#+id/carousel_layout_event"
android:layout_width="600dp"
android:layout_height="500dp"
android:layout_above="#+id/relativeLayout1"
android:layout_alignTop="#+id/carousel_layout" >
</com.touchmenotapps.carousel.simple.HorizontalCarouselLayout>
then image show as following way in carousel,
![enter image description here][1]
Here i want to increase the image width & height. It means one images must load fill with in the screen
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.showimage, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView1);
//LinearLayout rlayout=(LinearLayout)vi.findViewById(R.id.layout);
image.setImageResource(R.drawable.black);
orgWidth = image.getDrawable().getIntrinsicWidth();
orgHeight = image.getDrawable().getIntrinsicHeight();
imageLoader.DisplayImage(data[position], image);
imageLoader.getDimension(widthScreen, heightScreen);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
widthScreen,heightScreen/3);
params.width=widthScreen/2;
image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.FIT_XY);
//rlayout.addView(image);
return vi;
}
this way I add the imageview into carousel view.
how to do that. I asked question similer this one. But i didn't get answer. pls help me someone. pls.....
my imageview xml layout file..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/rlayouts">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="fitXY"
android:layout_alignParentTop="true" />
</RelativeLayout>
I think you should use a Horizontal oriented Linear layout inside a Horizontal ScrollView then you should add ImageViews with FillParent Height and Width in this Linear layout.
It would be great if you elaborate your question a bit more.
Related
I have created grid view for my wallpaper application but I am facing a problem with my layout. My grid view layout changes with different devices. I want the same view for all devices. Help me out.
This is my xml file.
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="30dp"
android:gravity="center"
android:horizontalSpacing="2dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp"
android:orientation="vertical"
android:id="#+id/gridview"
And this is Imageadapter file in which I have set my grid view.
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgGrid;
if (convertView == null)
{
imgGrid = new ImageView(current);
imgGrid.setLayoutParams(new AbsListView.LayoutParams(300,200));
imgGrid.setPadding(2, 2, 2, 2);
imgGrid.getScaleType();
imgGrid.setScaleType(ScaleType.FIT_XY);
}
else
{
imgGrid = (ImageView)convertView;
}
imgGrid.setImageResource(images[position]);
return imgGrid;
}}
replace this line
imgGrid.setLayoutParams(new AbsListView.LayoutParams(300,200));
with
imgGrid.setLayoutParams(new GridView.LayoutParams(70, 70));
feel change to pass layout params parameter. But don't give large values it won't look good on other devices.
i have simple gridview. it's elements have different height. for example in row there are one small element and one bigger, next row will align to smaller element and a part of bigger element is under the second row. how can i set the height of each row of gridview to be the height of the biggest element in row??
my gridview
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/new_small_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="2"
android:verticalSpacing="3dp"
android:horizontalSpacing="3dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:cacheColorHint="#android:color/transparent"
/>
For setting cell height, in GridViewAdapter when you write, for example:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
LayoutInflater cellLayout = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = cellLayout.inflate(R.layout.gridcell_layout, null);
}
TextView cell_title = (TextView) convertView.findViewById(R.id.gridview_cell_text);
ImageView cell_icon = (ImageView) convertView.findViewById(R.id.griview_cell_image);
....
Just substitute this line:
convertView = cellLayout.inflate(R.layout.gridcell_layout, null);
With this:
convertView = cellLayout.inflate(R.layout.gridcell_layout, gridView, false);
By this way, setting parent reference in "inflate", Width and Height about cell will set!
Here you can find why:
Layout problem with button margin
I need to display the image description under each image but I get an error that i can't cast GridView to TextView:
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView
android:id="#+id/main_gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="2"
android:padding="10dp"
android:verticalSpacing="30dp" />
<TextView
android:id="#+id/tvIconDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp" />
</LinearLayout>
Code:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
TextView textView;
if (convertView == null) {
textView = new TextView(mContext);
imageView = new ImageView(mContext);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
//imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
} else {
imageView = (ImageView) convertView;
textView = (TextView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
textView.setText(thumbDesc[position]);
return imageView;
}
convertView is going to be your parent View which in this case is a GridView. That is why you are getting the cannot convert error. You are trying to cast it to ImageView (and TextView for that matter).
You should put both the ImageView and the TextView together inside of a cell.xml layout file. Then inflate and populate that xml file during your getView() call instead of making new instancesof TextView / ImageView for each cell in your grid.
Here is a tutorial that covers these topics. He has even used your specific example (Text and Image in each cell). Once you complete this tutorial you should only have to modify it slightly to make the text go under the image if that is how you want it to appear.
<?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" >
<ImageView
android:id="#+id/venueImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I have an ordinary listview and a custom adapter using the xml above for the row.
I will only have 3 rows, but I want those 3 rows to have equal heights to fit the height of the screen's resolution. At the moment I don't even know how to set the height of the rows because setting the LinearLayout's height doesnt do anything.
You can set the height of your ImageView to get what you want. To set it programmatically, you can do this on the getView() of your custom adapter:
public View getView(int position, View convertView, ViewGroup parent) {
View cv = convertView;
if (convertView == null) {
cv = inflater.inflate(R.layout.listview_item, null);
}
ImageView venueImage = (ImageView) cv.findViewById(R.id.venueImage);
LinearLayout.LayoutParams vi_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, (int)(screenHeight*0.33);
venueImage.setLayoutParams(vi_params);
return cv;
}
You can get the screen height by adding this code on your main activity:
int screenHeight = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
Hello i have an activity that loads lots of images from the drawable folder, and put them in a gallery view from an Adapter. The problem is that there's too much space between this images.
Here's the getView i use:
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = new ImageView(mContext);
convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
ImageView iv = (ImageView) convertView;
iv.setImageResource(mThumbIds[position]);
return convertView;
}
Here is my xml layout:
<Gallery android:id="#+id/gallery"
android:background="#000000"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
/>
Is there any way i can get the images to be next to each other without having to create a new view for every image?
Best Regards.
Try using android:spacing in the layout file, to decrease space between images.