I need to have a layout for my widget, but I don't know how to arrage my images on widget screen.
I need to have 4 small Images on first row
then 2 Images on 2nd row
1 Image on 3rd row
and 1 Image on 4th row
Could you please someone create the xml file ?
You could use TableRows within a TableLayout.
Refer Hello TableLayout for an example.
Using the hierarchyviewer.bat in your sdk|tools folder along the way might be a very good idea as well.
LinearLayout(vertical)
LinearLayout(horizontal)
ImageView
ImageView
ImageView
ImageView
LinearLayout(horizontal)
ImageView
ImageView
ImageView
ImageView
Okay?
Related
I'd like to fill dynamic ImageViews in a LinearLayout. In addition i like to include at the top of every ImageView a TextView. Implemeting this in a static way with the xml file is no problem but I don't got any idea how to implement this problem?
For example I select 5 pictures out of the gallery and show all pics side by side. At the top of every pic you can see the name of the pic.
[EDIT]
LayoutInflater inflatter=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout myLayout = (LinearLayout)findViewById(R.id.mylinlayout);
// AbsoluteLayoute has got an ImageView and a TextView
AbsoluteLayout test = (AbsoluteLayout)inflatter.inflate(R.layout.test2, null, false);
TextView texttest = (TextView)test.findViewById(R.id.name);
ImageView image=(ImageView)test.findViewById(R.id.image);
texttest.setText("test");
myLayout.addView(test);
Sounds like you're trying to make a scrollabe list, where each item in the list is a picture and a title text, right?
Have you thought about using an ArrayAdapter in a ListView and in the adapter's getView() you can inflate a layout file that contains an ImageView and a TextView?
You could create a custom layout in xml with the ImageView and TextView arranged the way you want for each item.
AbsoluteLayout
TextView (above ImageView)
ImageView
Then, as you dynamically get the images, you inflate this custom layout using a LayoutInflater and assign the TextView with the desired text and the ImageView with the desired image. Next, you take the inflated view and add it as a child to the LinearLayout. Iterate through your images and do this and you should have what the desired appearance.
Edit: If you have many images that might require scrolling, you would have to wrap the LinearLayout in a ScrollView to allow scrolling if the LinearLayout gets too large.
As someone else just mentioned, a ListView will take custom xml layouts and inflate them the same way using adapters and such, and it will handle scrolling for you. ListView link and example.
I just wanted to insert an image in linear layout similar to this
Can anyone help me with this???
You are probably looking for ImageButton since your picture shows something similar to that.
Alternatively, take a look at ImageView
set layout's orientation to horizontal, then add 4 images in xml, one after another, add ids like image1, image2 etc, then call them in your onCreate like ImageView image
ImageView image1 = (ImageView) findViewById(R.id.image1)
and so on, then you can either set "src" attribute in yoru xml or say image1.setImageBitmap or any other method available in ImageView class to set the image you want from your res/drawable/
you can use ImageButton in horizontal LinearLayout
make background of the ImageButton #null
then put the margins between them
I've got next problem.
There is ImageView and button panel below it. I want ImageView to be as large as it needs, but if there is no enough space button panel should be present on screen and Imageview should be shrinked. What is the best solution for that?
Have a look to the android:layout_weight attribute.
What does android:layout_weight mean?
In case there is only 2 views in one layout (ie. Imageview and button) you can put both view in linearlayout and give value 1 for imageview weight layout (and doesn't give any value for the button)
I'm trying to draw an image into a LinearLayout, or TableRow, but I'm having already a XML FILE (I want to draw inside some LinearLayout). I don't know exactly how to do it. I was trying this:
TableRow mytable = (TableRow) findViewById(R.id.tablatexto);
ImageView myImage = (ImageView) findViewById(R.drawable.personaje1);
mytable.addView(myImage);
Thanks
Editing: I want to explaint it better. What I want to is creating a animation drawing images depending of a thread. So, I want to draw to some in LinearLayout from the Activity.
If you wan't to add dynamic layout in the container layout then you can use containerLayout.addView(childView);
childView is the dynamic layout which you can create using code or you can get a view of the layout using LayoutInflater class.
i added a lot of images into a linearlayout with horizontal orientation.
now i wanna set a gap between each image , is that possible??
thanks
Sure, add this to each of the ImageViews:
android:layout_mariginRight="10px"