Android Studio: View content in scrollView that is off the screen - android

I'm brand new to android development and I'm using both design view and text view to create a layout.
I've just used a scrollView element on the screen and have started to fill in all of the content. Unfortunately, the content is going off of the page (obviously will be scrollable when it's built). But I would like to be able to see the designed content before I run a build to see it.
Is there any way to expand my view of the scrollView element so I can see the content below the screen?

If you put all of the content you want in a separate layout using merge tag as the top level element you should be able to preview that layout in the preview window. Then just use an include tag to put it into the scrollView
eg
<merge xmlns:android="http://schemas.android.com/apk/res/android">
Your content here
</merge>
And
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/yourlayout"/>
</ScrollView>
See http://developer.android.com/training/improving-layouts/reusing-layouts.html

Well, obviously you can't scroll the screen in Android Studio, but you can set the visibility of any parent view to gone to see how your off-screen views look like, then change it back by removing the visibility attribute in xml.
You can also copy the views that are off-screen and paste them in another new layout for testing purposes only to see how it looks like.
Generally, you can just run the emulater in Android Studio and see how your design looks like too.

Related

Custom view hast strange layout behavior

Basically I have a custom View-Class (MessageViewAudio) which extends ConstraintLayout. This custom view contains another ConstraintLayout which contains another custom view (AudioVisualizationView) I made myself. The problem ist that the Top-Layer-Custom View (MessageViewAudio) always has some space to the right. I attached the information the layout inspector gave me. If you need any more code, just let me know.
As already said, I inspected the layout and tried different types of containers and manually tried to remove margins and paddings from every view mentioned above. But the layout inspector already says that there is no margin oder padding that could cause that strange behavior. There are two ways I got this to work One: is to remove all containers and just add the AudioVisualizationView custom view. Two: is to remove the property constrainedWidth = true from the LayoutParams of MessageViewAudio. Now I need constrainedWidth = true but I have that feeling that this property is kind of the problem, I can't just figure out why constrainedWidth results in this behavior.
With containers
Not Working
Hierarchy
ChatMessage
MessageViewAudio
audioContent
visualizationView
Without containers
Working
The only code I can provide for now is the xml of the views:
audioContent + visualizationView:
<com.jooyapp.jooy.custom_views.RoundedConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/audioContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundColor="#color/colorAccent"
app:radius="20">
<!--android:paddingStart="10dp"-->
<!--android:paddingTop="10dp"-->
<!--android:paddingEnd="10dp"-->
<!--android:paddingBottom="10dp"-->
<com.jooyapp.jooy.custom_views.AudioVisualizationView
android:id="#+id/visualizationView"
android:layout_width="wrap_content"
android:background="#color/light_grey"
android:layout_height="wrap_content" />
</com.jooyapp.jooy.custom_views.RoundedConstraintLayout>
All others are created programmatically
All in all my problem is that I don't understand where this space to the right of the custom view comes.

Android - White space on the right and the left of a LinearLayout

When I add element into a layout(in this case a LinearLayout), there is a white space on the two side of the element, but the attribute layout_width is "match_parent". Why?
Here's a screenshot:
http://s32.postimg.org/o4vr8kzbp/device_2016_07_30_001720.png
The code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="#color/blue"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
I found this lines somewhere on this site and it might be worth checking;
This is possibly because you are using the auto-generated layout files in Android Studio when starting a new project, which by default adds a margin of 64dp to tablet screens (the value found inside values-w820dp\dimens). – PPartisan 6 hours ago
Maybe you should check your layout's parent's layout in the host activity for one more time.
It is possible that the root layout does not fill the parent or that the child you are adding has a margin, to know exactly whats going on use the android tool called DDMS or Android Device Monitor (you can launch it from Eclipse or Android Studio) then click on Dump View Hierarchy. This will give you details on the size, padding, margin and other properties of every view on the view hierarchy
You should to check your code, may be you update margins of layout at your classes.
And try to check layouts of home activity, may be they are contains layout_marginLeft(layout_marginStart) and layout_marginRight(layout_marginEnd).
Also parent layouts may contains any white views on the sides or parameter layout_weight with specific value.

Multiple dialogs at once in Android

I'm trying to do something like the Jelly app to show multiple dialogs at once when a user clicks. Is there a way on Android to show multiple dialogs at once? So far I've only seen posts about having one dialog appear and then another based on user action. But I want them to all appear at once, similar to Jelly, and then have the user navigate through them using gestures.
Here's an image: http://www.8ms.com/wp-content/uploads/2014/01/view-answers-compose-answer-jelly.png
I figured this out --
Use a FrameLayout (http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/) to overlay views and have the answers appear and disappear on click.
Specifically with the Jelly example - One view is the main view (with the user's question) and then another view is the secondary view (with all of the community answers).
The secondary view starts off as hidden, so only the main view shows.
android:visibility="invisible"
Then when the user clicks the question in the main view, your OnClickListener for the main view can programmatically change the visibility of the secondary view.
view.setVisibility(View.INVISIBLE);
So the questions appear on top of the question. You can adjust the size of the secondary/question view so that you can still see the question, like in Jelly app.
The layout of the community answers is: (see code sample below)
HorizontalScrollView
--> Linear Layout
--> Custom Views (this is where each answer is shown. It could also be a Custom Dialog)
This is all within the FrameLayout.
On how to create a custom Dialog: http://about-android.blogspot.com/2010/02/create-custom-dialog.html
In your XML file, you would leave a blank space within the Linear Layout so that you could programmatically add in the answer views/dialogs because the number and content of the custom views would differ from question to question.
<HorizontalScrollView
android:id="#+id/notes_hsv"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginTop="100dp"
android:visibility="invisible" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- AnswerViews are added programmatically to this LinearLayout -->
</LinearLayout>
</HorizontalScrollView>
On adding views programmatically to a LinearLayout: Android: Add a textview to linear layout programmatically

Start each Layout with the same LinearLayout automatically

I Have simple question, i Have some linear layout with buttons on it.
how can I make this linear layout share to all my application layouts without copy it to the beginning of each layout.
I mean that any xml layout will start from the same LinearLayout, and will share the same references , like browser bar but when I launch to another Activity it's still visible.
Thank's guys
Use the include tag in each of your layouts
<include android:id="#+id/layout_id" layout="#layout/my_layout" />
see this blog post http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/

View entire content of ScrollView in Eclipse's graphical layout

I'm using Eclipse Helios 3.6.2 for Android development and whenever I design a layout in the graphical layout mode (not the XML layout), I can't see the entire content of a ScrollView in the graphical layout.
Specifically, when I'm using a ScrollView and the height of the ScrollView exceeds the height of the content view area (i.e., the phone screen visible in the graphical layout mode), I am not able to see the items that I have at the bottom of the screen.
In Eclipse Helios 3.6.1 there was an option called "expand to fit"; whenever I used to click on it, the phone screen increased in size to encompass all the elements that I had added. How do i achieve the same thing in 3.6.2?
There's no way to scroll the content inside the Android Layout Editor. What you can do, though, is create a new device simulation with a huge height, so you can see what is hidden in the ScrollView.
To do so, go to the dropdown menu below "Editing config" ang choose "Custom..." (top-left corner of the Android Layout Editor). Select one of your preferred resolutions (mine is 3.7in WVGA) and hit "Copy". The copied resolution will appear in the "Custom" group in the bottom of the list.
Choose your new configuration and hit "Edit...". In there, you can select the "Screen Dimension" property and change the value. I created a resolution 2000x480 (portrait). This way, I can see the whole content inside the ScrollView.
Hope it helps.
Use an included layout for the scrollview.
Move the entire scrollview layout in a separated file (ie: my_scrollview.xml).
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
...
</ScrollView>
The layout editor will then display the entire scrollview.
In the main layout use in place of the scrollview something like:
<include layout="#layout/my_scrollview" />
There was a button that allow to remove the clipping generated in a scroll view and show all the views that you have inside it.
In later sdk versions the button is removed, and the view mode is triggered if the scroll view is the root element of the view, so my solution when this doesn't happen (because you have a relative layout with some buttons over the view for example) is extracting the scrollview to it's own view, and including it in the original layout with an include tag.
My quick fix.
In the upper right corner of the graphic layout window you will see a drop down menu that shows what minimum version of android you are creating for. Make sure you have it set to at least android 2.1. I had an app at 1.6 and i had the same issue you have. swapped minimum build platform to 2.1 and it was magic.
Hope this helps.
If use Relative layout, you can use layout_marginTop negative, like that:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-500px"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout" >
Increase the layout_marginTop to move scrollview.
The drop-down on the left (under the text "Editing config: ...") allows you to change the simulated screen size in the graphical layout. Perhaps that is what you are looking for.
Just click on the Config window of the Graphical Layout and click on the preview for all screen sizes and u will be able to see your scroll
Use the android:scrollY in the ScrollView child and remove it before publishing.
<ScrollView ... >
<LinearLayout ...
scrollY="300dp">
</LinearLayout>
</ScrollView>

Categories

Resources