Compose button with layout - android

Is it possible to create a Button, whose background drawable is a layout?
For example, I would like to create a layout with some horizontal images and some textviews, and all the resulting view should be clickable all at once as a single button.
Would it be possible, and how?
Thank you.

LinearLayout yourLayout = (LinearLayout) findViewById(R.id.your_nested_layout);
yourLayout.setOnclickListener(...);

Related

Can we display emoji from keyboard into Linear Layout?

I'm trying to add emojis in a LinearLayout but I don't know if it's possible or not. What I want to do is when I press emoji it should appear in a LinearLayout rather than EmojiEditText. Is it possible?
I have searched for quite a while but I can't find any solution to my problem. Please suggest a library or solution that supports displaying of emojis in LinearLayout.
Rather than go for library, You can do from scratch as well.
Make one Linear layout and append that linear layout as the emoji is pressed.
For that, Give ID to the linear layout and append the layout by adding view to it.
LinearLayout linearLayout;
linearLayout = findViewById(R.id.linearLayout);
linearLayoutAmi.addView("VIEW_ACCORDING_TO_EMOJI");
Emojis are in text format, and LinearLayout does not have a text property unlike a widget. Wrap each selected emoji in a TextView and then add the textview into the target LinearLayout as child view.

How to combine dynamic an ImageView with TextView

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.

Layout design in android having TextView with image

how can i mange Textview in layout.? please help me..
how can i set textview and border then again textview.
Just create a horizontal LinearLayout, and add an ImageView, a TextView, a View with width 2dp and height match_parent, and a TextView as children.
Either repeat that for every row, or use the recommended approach of using a ListView with the above mentioned layout as rows.
I'd use two compound TextViews: Just create a horizontal LinearLayout, and add a TextView with drawableLeft="#drawable/icon_location" and another one with drawableLeft="#drawable/line_vertical" as children.
For both, a drawablePadding="8dp" or whatever you like best

How to add blocks of linearLayouts and is there a better way?

This is the main idea of what I am trying to do.
I would like to ask you what is the best way to make such a design. the problem is that these gray/black blocks might not show up (user will choose which should show up). So I would like to find out do I need to make these 3 text views inside linearLayout programatically? Is there anyway to create some sort of template which I would only have to edit by setting new texts for textViews and add them to some sort of layout?
Another option is to just have a LinearLayout and an xml for the row entry. Then you can do:
LinearLayout layout = (LinearLayout) this.findViewById(R.id.your_layout_id);
List<Blocks> userBlocks = getMyUserBlocks();
for(Block b : userBlocks) {
View blockView = LayoutInflater.from(getBaseContext())
.inflate(R.layout.your_row_layout, layout, false);
TextView someData = (TextView) blockView.findViewById(R.id.your_text_view_id);
someData.setText(b.someAttribute.toString());
layout.addView(blockView);
}
You will need a separate xml layout for the block row.
You can use a ListView with large dividers. Your dark gray blocks are the row views, and you can just append them to a dataset and update the adapter for the ListView. For the dividers, see setDivider() and setDividerHeight().

How to set two layout one at top and anther at bottom

hi I have 2 layout inside a framelayout and i want one linearlayout at top and another at bottom where i will specify height for both the layouts
and how to set this parameter for the linearLayout "layout_gravity " by code not by XML
Use a surfaceView , the SurfaceView allows you to stack in the Z order.
Docs
make sure your surfaceView is under the views of the views you want to stack.
Hope this helps
first fetch the layout from id.
LinearLayout layout = (LinearLayout)findViewById(R.id.IDOFLAYOUT);
//the set the gravity by this method
layout.setGravity(Gravity.CENTER);

Categories

Resources