I was wondering if there is a way using which we can create 2 drawableLeft in our android layout. I have a scenario where i need to use 2 drawables. Anyone with any suggestions, drop them down please.
Edit: This is the layout that i want to design.
If you are using this view in only one place then you could just use LinearLayout with horizontal layout. and place 1 ImageView, TextView or Spinner [as per your requirement if the country code is selectable then you should use spinner instead of TextView for country code view] TextView and style them as needed. As in following picture:
If you need to use this layout in multiple place you could implement Custom View with the same layout file. Check how to create Custom View from this answer.
Related
I want to know how is possible to achieve a arrow-based layout like this :
Any idea about what Layout is using this app in order to achieve that layout ? It seems like a kind of Staggered Grid Layout maybe ? Or maybe is using a library or a custom layout ? How can I achieve something similar ?
so here is how I would do something like this.
I make a bunch of custom views.
custom view #1:
PokemonView.
This is a regular Constraint Layout or CardView that contains all the items to show the pokemon, and its name, and all the other stuff.
custom view #2
EvolutionPokeminView.
this is a custom constraint layout that contains a PokemonView, and The Arrow ImageView (and TextView below), and helper methods to place the arrow in different directions.
for example:
setArrowDirection(int direction) \direction is some kind of enum for all directions (top, topLeft, topRight.. etc
another helper method is setArrorPosition,
setArrowPosition(int direction)
then you use the arrow direction method to set the correct arrow image into the arrowImageView, and you use the arrow position method to use ConstraintSet to programmatically set the correct position of the arrow in relation to the pokemon image.
after that, you prepare a few common layouts to use with different sets of data and populate them accordingly.
Things you'd need to know to make this approach work.
How to Make a Custom View in Android.
How to use ConstraintLayout effectively.
How to use ConstraintSet to programmatically edit ConstraintLayout constraints.
I want to add three textViews in a single button.
I can do it using linearLayout as an XML file and then inflating it to my custom button class but somehow when I set click listener on this type of custom button it won't work.
I desire for a much better option, maybe extending the Android button class and then change it according to my requirement, but unable to inflate my button to my desired views.
Please assist me on how to do this.
Creating LinearLayout and setting style="#android:style/Widget.Button"
Did the trick for me.
You can design your layout with the three textviews as usual. For emulating click, set a StateListDrawable as the background of the root container. Put this in any layout (or use <include>) and attach a clickListener as usual.
You can simply use LinearLayout with 3 textview as its child and set click listener on it. No need to create custom button class. But I do not know exact requirement so need more details for creating custom button class.
Ho can I design a page like this
To achieve this layout simply make a GridView with custom layout. The custom layout could contains two child LinearLayout and The desired ImageView and TextView inside them. If you aren't familier with custom GridView just have a look on the simple tutorial,
https://www.caveofprogramming.com/guest-posts/custom-gridview-with-imageview-and-textview-in-android.html
For designing the layout see the below image,
You can make use of a gridView or RecyclerView(with a gridLayoutManager) and each item in your grid will contain properties like name,image,bgcolor1,bgcolor2 ..desing a layout and change the color,image name at runtime..
I need to implement such a element - TextView of predefined size with white border line at the bottom. Inside of the TextView a button with predefined style and size should be. TextView shouldn'y be clickable and button should be. I see some possible solutions:
1) implement TableLayout and put all my buttons into the table's row. But there's not nice solution - my layout becomes too long. So I think about another solution.
2) make my element as a custom view. But the problem is that I need to use a lot of these elements through my app and I need use onClickListener to each of them. I know how to implement onClick() method for all items but how I can use singular onClick() method for each of the item? And how should I build this custom view - should it be extending from RelativeLayout, where TextView and Button with defined properties should be put?
I also thought about using for the button, but in this case my TextView will be also clickable.
Tell me please what approach is less complicated and more convenient.
I used another way if solving this issue. I put buttons and other control elements into the TableLayout with predefined TableRow style. In this case I do not need implement TextView and borders margins which I need I build with corresponding TableRow style.
How the ways that I can make this custom Label?
Is it a TextView with a background image?
You wont be needing a Custom View to create this.
Use a TextView with a background image and a Right Image property. Use RelativeLayout to overlap it over the coffee image.
In case you have to use it in more than one place extend a frameLayout to create a custom component.
It could be just a Imageview above another ImageView (coffee), which is above the TextView below.
You can look at Android layout and UI.
Or, it is just a mobile version of a web page, then you can look at html to find out how to do it.