I'm trying to do something relatively simple but really struggling.
I want to do something like this:
Explanation:
I want to create a block of fixed height (say 100dp) that is separated into three cells (that are separated by the green dashed lines shown in the picture above). The cells should also be of fixed size
The text in each block would be updated at runtime, and I want an arbitrary number of these blocks
Thanks a lot in advance.
I would suggest that you use a cardview embedded in a recyclerview. then you can set the number of such blocks in run time.
If you wanted to fix the number of blocks, then you can use Relative Layout.
Sample Relative Layout can be :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/container"
android:orientation="vertical">
<TextView
android:id="#+id/largetxt1"
android:layout_width="300dp"
android:layout_height="50dp"
android:text="TEXT"/>
<TextView
android:id="#+id/smalltxt1"
android:layout_width="300dp"
android:layout_height="20dp"
android:text="MORE SMALLER TEXT"
android:layout_below="largetxt1"/>
<Button
android:id="#+id/button1"
android:text="CLICK"
android:layout_toEndOf="#id/largetxt1"
adnroid:layout_width="60dp"
android:layout_height="70dp"
/>
.
.
.
.
..
</RelativeLayout>
This is the sample for the first set of boxes. You can set use the same and repeat it for the number of sets you wanted. Make sure to place layout of views correctly
you can use weightSum and layout_weight attribute xml file
Related
I am working on a text view which shows the number of selected items (from a multiple choice list) with the number having a circle around it. I thought to add the circle by using the setCompoundDrawablesWithIntrinsicBounds (as I don't want to have 2 separate text views to achieve the desired look), but my question is if it's possible to somehow apply some text (in this case the number) over the circle image or if not, what would be the best solution for the label I have in mind?
I need to implement something looking like this:
What is your advice? Thanks for the help in advance!
You can use LinearLayout for that instead of single TextView implement click of LinearLayout.
For XMl use this:-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/line">
<TextView
android:id="#+id/txtNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_bg"/>
<TextView
android:id="#+id/txtDropDown"
android:layout_width="0dp"
android:weight="1"
android:layout_height="wrap_content"
android:drawable_right="#drawable/arrow_down"/>
</LinearLayout>
I have the Views attached to each other in the following order:
Activity->RelativeLayout->RelativeLayout->Text
When I change the Y of one of the Text attached to the inner RelativeLayout, parts of it are cut.
Here's a screenshot:
http://s28.postimg.org/ypmvrjz25/image.png
I'm coding purely in Java, no XML.
What's going on?
It looks like one layout is overlapping on another because the menu bar is pushing it down. If you just want the text centered I would suggest setting that in the parameters like so.
android:gravity="center"
This places the text in the center if that is what you want.
<?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"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView12"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
As #Jonathan Whalen suggested you probably have some overlap, I suggest you to change your relative layouts background color to see wich one is overlapping the text. Also try to not use fixed height for the layouts but use wrap_content instead, as fixed dims are frequently the cause of layouts overlap.
I have a table row in a linear layout
The table row is set to fill parent
I have three objects inside the tablerow a textview then a editbox and then a buttong
they all line up horizontally
i want the textview on the left to be fixed at 100p width
I want the button on the right to be fixed at 50dp width
how do i set the editbox in the middle so that all three fill the width of the screen which might vary from device to device
I have tried various combinations of match and wrap but cant seem to get it
Any ideas
Mark
You have to use layout_weight for particular child of your view group or use relativelayout may solve your problem and please post you layout XML.
Try the following, using layout_weight:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="#+id/textView" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_weight="1" />
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/button" />
</LinearLayout>
That's when LAYOUT WEIGHTS come in handy.
For the fixed elements, just assign width & height as usual.
For the elastic ones, set "0dp" as the size you want to be elastic, and enter a weight in the weight field (layout parameters of a linearlayout).
Which weight?
If you only have one elastic element, it doesnt matter. If you have 2, then the available space will be distributed proportionally between weights. So if you wanted 2 elastic elements, one twice the size of the other, you'd assign weights 1 & 2.
By the way, heavy use of LinearLayouts with weight are somewhat discouraged because it takes Android twice the time to calculate their size. If your table has a lot of rows, you will certainly notice it's not as fast as fixed elements.
I have multiple ImageViews which are transparent and are meant to over lap one another. I am aligning then to one another but one problem presist. How can I set the order in which they are layered? Ive tried revising the code in both xml and how the images are set in the actual java code...
I have tried FrameLayout but maybe Im not using it right...here is my implementation:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".RadarActivity" >
<ImageView
android:id="#+id/imageview_topo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageview_counties"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="45dp"
android:scaleType="center"
android:visibility="invisible" />
No matter what I do...imageview_topo is always placed on top. Even in the code i have instantated topo first and retrieved its image first!
Thank you!
I referred a site here that says:
If multiple child views exist, then they are drawn, in order, one atop
the other. This means that the first view added to the frame layout
will display on the bottom of the stack, and the last view added will
display on top.
You can check this site too: http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/
May be i can help you more if you show the screenshot of your UI.
I am trying to make two TextViews that will be on the same row. The first one should be left aligned and the second one right aligned, when one of them becomes to big the first one (the left aligned should go on new row). I was able to make the first one to go on new line when the second TextView (the right aligned one) became too big but the problem is that it doesn't display the whole information from it. So anyone has any ideas. I'd like it to be with RelativeLayout but any help would be appreciated.
You should play with android:layout_weight to acheive this , this is how it should be :
<LinearLayout .....
android:orientation="horizontal" >
<TextView android:id="#+id/txtView1"
android:layout_height="wrap_content"
android:gravity="left"
android:text="TextView Left"
android:layout_width="0dp"
android:layout_weight="1" />
<TextView android:id="#+id/txtView2"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_width="0dp"
android:text="TextView Right"
android:layout_weight="1" />
</LinearLayout>
You should try putting the two textviews into a linearlayout, set the layout_weight="1" on both textviews and their layout_width="0".
give weight = 1 for both text views....
if it does't work....change relative layout to linear layout or table row and give weight to 1 for both text view
Put your TextViews in LinearLayout and set layout_weight=1. it will solve your problem.