How to stop a textview pushing layout off of screen - android

I am building a app and I just need some help with the attached screen shot.
Currently I have 5 Plain Textfields with the last 2 being textMultilines. I have a Relativelayout with a button placed at the bottom for the user to press submit. The problem is when the textViews above are filled in, especially the multiline ones, it will push the Relativelayout and button off the screen.
How can I stop this from happening
Picture of layout

Either You should fix the height of multi lines text or you can simply use Scroll View and put all the text view and button in same relative layout

You can make them Scrollable by adding ScrollView around them.
like
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//all your views here
</LinearLayout>
</ScrollView>

Related

Android buttons are cut off (LinearLayout horizontal)

In my app I am calling API to get list of people with some informations (address, phone numbers etc.). Under every phone number, I am creating programatically 3 buttons (add to contacts, edit and call). Problem is, that last button is cut off (small screen). I am using Linear Layout horizontal.
Is there any way to control size of screen and if needed, put last button to second line? When I rotate screen to landscape, I have enough space, so buttons should stay in one line.
Now, I am using horizontalScrollView with visible scrollbar. It's working, but I am not very satisfied with it.
Thanks for help.
I'm not really sure if you can do that with LinearLayout. But you could do that using FlowLayout. Check this link: https://github.com/ultimate-deej/FlowLayout-for-Android.
This layout moves the buttons to the next line if there is no space for them on the screen.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="1" />
</LinearLayout>
the weight attribute will automatically adjust your button size
make sure you set width to match parent for all buttons.
Best to create a new variant of the listitem layout for smaller screenshots:
layout-w200dp/listitem.xml : layout with 3 buttons on one line
layout/listitem.xml : layout with buttons on separate lines
Android will then choose the multiline layout when the current available width is smaller than 200dp. (Note that you can still tweak the 200 to a different value)
Alternatively you can also use an alternatieve linearlayout which does the wrapping for you: Flowlayout
This is probably more complicated to achieve that you wan't it to be but the best shot is to use some adapter based solution:
GridView - this is the old solution, better go for the 2nd
RecyclerView with StaggeredLayoutManager setup to your needs
Simple solution is using android:layout_weight="1" and android:layout_width="0dp" as params for each button in your LinearLayout but then they will fit the whole screen and take the same percent of the width, and if the screen is too small buttons might get cut off.

How to click a view that is behind a scrollview

I have to an EditText behind a ScrollView
I cannot click the EditText anymore. The ScrollView is intercepting it I think. I tried the code below but it doesn't fix it.
Any suggestions?
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true" >
Things to try:
The parent view can influence the position of the views. For example
in a FrameLayout all of the views get stacked in the order they are
placed in the layout file (so your issue could be fixed by
rearranging the order of the EditText in relation to the
ScrollView).
You might try to call editText.bringToFront() to force the
EditText in front of the ScrollView.
If you disable the touch-based listeners (OnClickListeners, etc) on
the ScrollView or the container it's in then the action should "pass
through" the ScrollView and allow you to interact with the EditText
behind it. I found this out the hard way when I was trying to make
the opposite scenario work for me (I wanted the top level view to
consume the actions and not fall through to the view behind it).
These solutions worked for me in the past in different scenarios.
In my case I replaced android:layout_height="match_parent" to android:layout_height="wrap_content" and views inside ScrollView become clickable. Hope this helps.
My code:
v<ScrollView
android:layout_width="match_parent"
android:layout_height="WRAP_CONTENT"
android:id="#+id/svTabActions">
<View>...</View>
</ScrollView>
Try placing the editText inside the scrollView.

Move focus/navigate, with d-pad, between LinearLayouts in same fragment

I have a fragment containing several layout that I want to move the focus between. The app is operated with a remote containing a D-Pad (up,down,left,right & enter).
Both "view groups" are wrapped in a FrameLayout because the second one i overlapping the first one which is stretching the whole page. The views layout looks like this:
<FrameLayout android:id="contentSurfaceWrapper">
<HorizontalScrollView android:id="contentSurfaceScroll">
<LinearLayout android:id="contentSurface">
<!-- This layout is populated with child layouts (LinearLayout) programmatically -->
<!-- Those layouts are: clickable, focusable & focusableInTouchMode -->
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
<FrameLayout android:id="navButtonsWrapper">
<ScrollView android:id="navButtonsScroll">
<LinearLayout android:id="navButtons">
<!-- This layout is populated with child layouts (LinearLayout) programmatically -->
</LinearLayout>
</ScrollView>
</FrameLayout>
Image of how it looks:
I'm able to navigate to the view: contentSurface and between all its childs with the remote from the action bar in the top of the app. But, now I want to navigate from the first view (contentSurface) and its childs to the second view (navButtons) and its childs. But I doesn't seem to be able to move the focus some how. I want the focus to be moved when reaching bottom in the first layout and back when reaching top in the second layout.
I've tried to make the children in the second layout also clickable, focusable and focusableInTouch but it doesn't seem to work.
So.. I solved it this way:
For the first child in both views, which I append programmatically, I'm setting an ID.
This ID is then used with android:setNextFocusDownId on the items in last row in top layout and in android:setNextFocusUpId on items in bottom layout on first row.
This way I can switch focus in between the childs in both views.
More info about android:setNextFocusUpId etc.
http://developer.android.com/reference/android/view/View.html

creating a camera view with button for android

i have set up an activity that loads up the camera and allows me to preview it but i need to add a button to the screen but the only way i can get the screen to display is by using the following layout:
<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.view.SurfaceView>
is there a way for me to add a button to the view?
Put your SurfaceView and button into a RelativeLayout. Both of those types of layouts allow views to overlap so your button will be on top of your SurfaceView. The set up would be something like this
<RelativeLayout>
<SurfaceView></SurfaceView>
<Button></Button>
</RelativeLayout>
DeeV's answer is correct for the RelativeLayout part. The FrameLayout isn't intented to contain multiple children. So the RelativeLayout is the way to go.

Scrollable FrameLayout

Alright, so I followed the Tab Widget tutorial to create some tabs for my application. In one of the tabs, I have a TextView with a lot of text that I'm debugging with. But, with all of the text, all of the info doesn't show up on the screen. I figured that I could scroll down to see the rest, but I cannot scroll. Any idea on how to make it so that I can scroll down my FrameLayout so I can see the rest of my text?
You can surround the view that you want to be scrollable with a ScrollView, as below:
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff">
// the views here that you want to make scrollable
</ScrollView>

Categories

Resources