Android: Dynamically adding textviews to a scrollview - android-layout

I am working on an application that functions like a text messaging app. I am working on the layout of the app now. In the XML file I have an edit text on the top of the screen and one on the bottom of the screen. I want to dynamically create a scrollview that would be between the 2 edit texts. The scroll view would enable to scroll through multiple messages of the app. When I try to create the scrollview and textview dynamically it replaces the edittexts and they disappear.
So my question is how would I go about preventing the edittexts from disappearing and adding a scrollview in between the 2 edit texts ?
My code is like this:
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addview(ll);
TextView tv = new TextView(this);
tv.setText("Dynamic layouts ftw!");
ll.addView(tv);
this.setContentView(sv);

What you are asking to do is build a ListView. ListView'ss have every function you require and more. Further, with the adapters, they are pretty quick. Here is a decent turorial on using ListViews.

Related

Vaadin 8 View: No horizontal scrollbar on window resizing

I have a Vaadin 8 application with several views.
public class ViewName extends Panel implements View {
There is a VerticalLayout as main layout in the panel.
public ViewName() {
setSizeFull();
VerticalLayout mainLayout = new VerticalLayout();
setContent(mainLayout);
Then I have many different layouts (HorizontalLayout, GridLayout) or Components such as Label being added as components to the mainLayout. For the HorizontalLayouts I often do the following to use the full width of the screen:
hLayout.setWidth("100%");
I have a lot of icons, grids etc. Everything is OK as long as I don't resize the window.
When I resize the window to a small size I get a mess (icons, text etc. on top of each other) and no horizontal scrollbar. (However, the grids get horizontal scrollbars.) I have tried many things to fix this. If I add
mainLayout.setSizeFull();
or
mainLayout.setWidth("100%");
I have a mess on the big screen already. I also tried the CSS for the mainLayout as described here. I get several scrollbars but none for the window itself!
The only component that resizes correctly is a Label added to the mainLayout, e.g.:
Label title = new Label("Some text",ContentMode.HTML);
title.setWidth(100, Unit.PERCENTAGE);
mainLayout.addComponent(title);
mainLayout.setComponentAlignment(title, Alignment.MIDDLE_CENTER);
I also noticed that anything in a GridLayout seems to stay in place after resizing but is not vissible since I have no scrollbar. However, icons in a HorizontalLayout get on top of each other.
What is wrong? Please, I need a general instruction on which layout I should use as main layout for my view panel, how to size the components and how to get ONE horizontal scrollbar for the main window if necessary.
The problem is that you are setting the width of your mainLayout to the width of your view. This means, that your mainLayouts width will never be bigger than your views width. So no scroll bar will appear.
According to the information you posted, changing your mainLayouts width to undefined should fix the problem.
mainLayout.setWidth("-1px");

Gtk3 - Prevent TextView to make Window grow

I am currently trying to create a small note app with GTK3. It's basically a Window that sticks on your desktop and is undecorated. Currently it contains a Button and a TextView which reside in a ListBox. However as soon as the TextView has more rows of text than space for rows of text, the TextView and the Window will grow. The Window will actually grow bigger than the screen is.
What I have tried:
window.SetResizable(false)
using SetVExpand(false) on the Window and the ListBox
Wrapping the TextView in a Layout, which the documentation claims is a scrollable container (I probably misunderstood)
I simply used Gtk.ScrolledWindow.
var hAdjustment, vAdjustment *gtk.Adjustment
textViewScrollPane, _ := gtk.ScrolledWindowNew(hAdjustment, vAdjustment)
textView, _ := gtk.TextViewNew()
textViewScrollPane.Add(textView)
The example is Go, but it doesn't really matter.

Is this layout possible to make, FadingActionBar w/ ViewPager?

I've got an layout which i really would like to use but I'm not sure it´s even possible!
I have tried FadingActionbar from github which works when I have a scrollview for content, but when I change to an ViewPager none of my fragments in it seems to load, and I¨m not able to swipe either to the sides or swipe up the top image.
My viewpager will consist of 3 views. One is an scrollview, and 2 of them are listviews.
I hope you understand what I want to achieve :) When swiping up I want the imageview to slide in under the actionbar and then stop when the PagerSlidingTabs are just under the acitonbar.
Mockup of what the layout looks like
This is the related github issue
https://github.com/ManuelPeinado/FadingActionBar/issues/23

Android UI: Button with shape inside?

I need to create a button that looks like this:
button
I was hoping to create it without using images. To create the pink part, I wanted to use a drawable.
How can I include a shape drawable within a button?
You can create a Layout, set background color for that layout as you wish. In that layout add two textviews. Set background for one layout pink. add another under the first textview. Then you can set onClickListener on layout. It'll work same as that of button and it'll be easy to change colors and text programatically.
Try using an ImageButton and setting android:src to point to your ShapeDrawable resource.

How to have multiple layouts in one activity in android?

What i want in my activity is two buttons on the top in one single line.. and below that i want a framelayout in which i want an imageview and i wil add my custom view on the top of imageview. I tried a lot but i am having a lot of confusion.
Shown in the image below is somewhat like i want.
I want to use framelayout because i want to add my custom view over my imageview. But if i add button on framelayout it comes above the image. It is getting really confusing and messy for me.
I did'nt know that we could nest two layouts in a single activity. I nested LinearLayout with FrameLayout and my problem got solved.. Cheers!

Resources