Very general question: I have multiple widgets in a ScrollView Android app. A standard ScrollView, mobile can show say 720 lines and user can scroll down then back up going thru multiple widgets (text panes, buttons etc). Problem is that I want to add a WebView that will display an HTML table; the height of this HTML table will be variable size.
Is there a way to change the height of the WebView based on the size of the HTML table it should display?
Yes, you can get a reference to the WebView, then set the height of it, with the setHeight attribute.
Maybe you would be better off letting the container take care of that for you, and set the attribute to "wrap_content".
I guess, you need to calc web-view content size (here and here and enter link description here), than set webview size to content fits (maybe here). In that way you should have only scrollview scrolling.
Good luck
Related
Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method
I'm experimenting a login screen: https://snack.expo.io/#lucaszanella/login-screen-test-zanella
(some image sources were removed because I cannot upload them to snack and others I changed to random images from url)
Open login_screen/components/Form.js. Well, as you see, the UserInput inputs and SubmitButton button are spaced, but I didn't tell them to. I already tried all justifyContent properties and they don't even move the components. Looks like they are justified (not even equally).
What is going on? If you know some concept about flexbox that I'm getting wrong please tell me.
Children of a flexbox share the parent's flex area in proportions. You have set Logo to flex:3, Form to flex:7, and SignupSection to flex:1. Thus, 7 + 3 + 1 = 11, therefore, Logo takes 3/11, Form takes 7/11, and SignupSection takes 1/11 of the parent's flex area in the specified direction.
Within Form, you've set UserInput to flex: 1. So the children (UserInput) of Form will equally share (and fill up) the flex area (7/11) that Form has acquired from its parent. This is why you see the space between UserInputs. To understand this better, try replacing UserInputs with simple Views with different background colors and you'll see what's going on.
Solution: Reduce flex on Form and apply margins if required.
EDIT
Alternatively, you can set fixed height (in case of flexDirection:'column' of parent) or width (in case of flexDirection:'row' of parent) to the children.
Hope this helps.
Now I need to decide what widgets to use. There are a brief text description from an SQLite database and an image from an SD card or from the Internet on the screen.
I think that it would be better to use a single WebView to show the content than a TextView, an ImageView, and a TextView again. Are there any better ideas?
Here is a picture I created on Lucidchart.
Using WebView is not a good idea, Put the three components within a RelativeLayout and in a ScrollBar so that you can extend the elements without worrying about the size of the text as well as image size. And also webView will not render text perfectly.
Either option is fine. If the text in the database is in html format, you should use a webview. If not, you can use two textviews and one imageview.
With the WebView: you can justify the text, but it will not be a very clean solution if you want to resize the image for different screen sizes/resolutions.
I'm trying to use a custom font with the text in my Widget. Since the RemoveViews is very limited and doesn't support custom fonts in the TextView options, I found this post that showed a clever way of getting around this. Essentially, instead of using a TextView I use an ImageView and render a bitmap of the text in the custom font and set the ImageView's bitmap to the rendered image. Now the only problem is that I need to determine the width to render the Bitmap so it fits perfect in the fill_parent on the ImageView. So how do I get the width of a widget?
I'm trying to use a custom font with the text in my Widget.
Note that the correct term is "app widgets". Widgets are subclasses of View. App widgets are the things that go on the home screen. See: http://developer.android.com/guide/topics/appwidgets/index.html
So how do I get the width of a widget?
You don't. You know what you asked for via your metadata. What you wind up with is up to the home screen implementation, and there is no way to retrieve that information. That goes double for widgets that the user resizes, either because you indicated that you support resizing, or the home screen just decided to roll that feature themselves.
By using WebView, I have loaded some html content contains image(large
size, for example, 800*600) and text.
For text, it can perform line wrapping automatically.
But for image, it will enable the horizontal scroll even if
"setHorizontalScrollBarEnabled" is set to false.
Is there any method to force auto-fit in the WebView?
Thanks!
You can parse the HTML content before loading it into the WebView and change the image(s) size according to screen resolution (that you can detect)