so im trying to use a relative layout (for basic app tabs at the bottom of the screen) and it is not showing when i place it inside the LinearLayout after 2 other layouts (a LinearLayout and a ScrollView). The ScrollView contains several textViews and scrolls nicely on its own and the linearlayout before it also works nicely, but the relativelayout that i have tried to place at the bottom of the screen does not work.
Here is the general code for what i am trying to do:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="#drawable/common_bg"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="50dp">
<TextView android:layout_height="50dp"
android:text="Heading"
android:gravity="center"
android:textSize="17dp"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_width="fill_parent">
</TextView>
</LinearLayout>
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_gravity="top"
android:layout_marginBottom="60dp">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:paddingTop="15dp"
android:layout_weight="1"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold"
android:text="#string/text"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/bottomMenu"
android:layout_width="wrap_content"
android:layout_height="60dp" />
</LinearLayout>
UPDATE: the Relative layout that im using is custom in a way that i cant actually show the code for it here, but it contains a radio group with several buttons.
UPDATE 2: Ok, so I solved the problem by manipulating the layout_height="wrap_content" on the 3 layouts (the first linear, the one holding the scroller, and the bottom relativelayout) as well as manipulating the layout_wieght of each of them until I was satisfied with the way it looked... it doesnt seem like this is the best possible solution, but it worked so i cant complain too much lol...
The relative layout in itself wont be displayed in an xml graphical layout or when you are running the app, it needs a child element to occupy the parent layout, try putting a text view inside the relative layout, it'll be displayed, position it right below the linear layout having the scroll view, it'll work properly, i just tried it with your code and it works
Related
I am struggling to find a solution for one of the Android Studio (Kotlin) class problems by Google: how to add another image that scrolls down with the first ScrollView. I created a LinearLayout that has two ScrollViews within it. The first ScrollView has a large amount of text which scrolls down perfectly. However, in the second ScrollView, for the image above the text, it does not scroll down with the text.
Here is a view of the Design element of the activity_main (the green bar below the star is ImageView1 which is in the second ScrollView):
Here is the code for the ScrollViews in my activity_main:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="#+id/bio_scroll2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/button_onoff_indicator_on" />
</ScrollView>
<ScrollView
android:id="#+id/bio_scroll"
android:layout_width="match_parent"
android:layout_height="463dp">
<TextView
android:id="#+id/bio_text"
style="#style/NameStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.2"
android:text="#string/bio" />
</ScrollView>
</LinearLayout>
Some guidance will be greatly appreciated.
The reason I told you to use only one ScrollView is that you don't need two. You can use any number of views in a Scrollview, just make sure the child of ScrollView is a Layout. You can use any layout and then put whatever you have in that layout. That's how ScrollView is used.
As the official docs of ScrollView state :
Scroll view may have only one direct child placed within it.
To add multiple views within the scroll view, make the direct child
you add a view group, for example LinearLayout, and place additional
views within that LinearLayout.
So, change your code as :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="#+id/bio_scroll2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/button_onoff_indicator_on" />
<TextView
android:id="#+id/bio_text"
style="#style/NameStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.2"
android:text="#string/bio" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Furthermore, You can remove the root LinearLayout if you don't want to add any other view in it and that will make the ScrollView the root layout.
Also, the height as match_parent doesn't work in ScrollView and it works only as wrap_content or any fix size so if you want to make it take the full height of its parent, you've to use android:fillViewport="true" in ScrollView's tag and height of its parent should be match_parent.
i developed a keyboard that works without issue on MM and lower. By the way on Nougat i have a layout issue, check this images to understand better: http://imgur.com/a/IHfeZ.
The 1st image is on Nougat ( the popup isn't showed completely) the 2nd is like appeared on MM ( all the lines are showed correctly ).
I used this xml to customize the popup:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/aosp_pressed">
<android.inputmethodservice.KeyboardView
android:layout_gravity="bottom"
android:id="#android:id/keyboardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keyPreviewLayout="#layout/preview"
android:keyBackground="#drawable/key_background"
android:keyTextColor="#fff"
android:background="#color/aosp_background"
android:keyTextSize="25sp"/>
<ImageButton android:id="#android:id/closeButton"
android:background="#color/aosp_pressed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:clickable="true"
android:src="#drawable/ic_close_black" />
</LinearLayout>
As you can see the issue is caused by the position of the popup that isn't showed outside the keyboard. How can i solve this issue?
Thanks in advance to everyone.
What is your #layout/preview like?
My theory is that in between Android 6 and 7, the time when wrap_content chooses it's size changed.
Before when using
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:id="#+id/xxxxx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout> //PARTIAL CODE!
there were no problems in 6.0. The text view would expand to fit the text and then be centered.
However, in 7, the text gets displayed completely vertically suggesting that the initial LinearLayout was getting set to a width of 0 and not adjusting.
Try playing with the height in your #layout/preview, or in your closeButton. Set them to manual heights and see if things change accordingly!
I am developing custom menu item by calling action layout, but when i am taping that action menu that pressing color is not applying total height giving some top and bottom margin.
Below is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:minWidth="56dp"
android:id="#+id/voicemailNotificationCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/ab_pressedicon_bgcolor"
android:contentDescription="#string/voicemailnotification"
android:src="#drawable/ab_voicemail">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vmNotificationTextCounter"
android:text="1"
android:visibility="visible"
android:layout_alignRight="#+id/voicemailNotificationCounter"
android:layout_marginRight="10dp"
android:gravity="center"
android:textColor="#fff"
android:includeFontPadding="false"
android:background="#drawable/notification_alertbg"
android:textSize="12sp"/>
</RelativeLayout>
Part of the problem is that you're not using an ImageButton.
Combining an image with text is possible with an ImageButton. You can even independently adjust the text and the image inside that ImageButton.
Hopefully, an ImageButton will work inside an action menu, I haven't actually tested that part yet.
I'm trying to create a new layout. My last layout that I used was GridLayout and basically created a table with 3 columns and 8 rows. With rowspan I was able to achieve the look that I wanted within Eclipse however, my screen is a little longer on my phone then Eclipse is and it shows that column 1 and 2 look good, but 3 was stretched to the right.
The new layouts looks like this:
** You can see the arrow on the right side is well over the edge of the screen and I don't know why. I'm trying to create a layout that when used on different devices will scale appropriately.
The XML code is as follows:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightsum="1.0" >
<ImageView
android:id="#+id/arrowLeft"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:src="#drawable/arrowleftoff" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".34" />
<ImageView
android:id="#+id/arrowRight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:src="#drawable/arrowrightoff" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</LinearLayout>
</TableRow>
</TableLayout>
The issue was caused by a lack of understanding how Eclipse works regarding layout. First, the screen shown in the Eclipse visual layout editor is an "example" of what it would look like given the selected device at the top of the window (in my case Nexus S).
Second, the Layout I was using was not anchoring to certain elements or to the parent. Therefore when the screen dimensions changed, the layout changed with it.
Conclusion: I am now using and understanding RelativeLayout and it works wonders once you figure it out.
Here is a great resource which really helped me understand what was going on: Mobile Tuts Plus: Layout Basics
Below is the xml layout for my Android App. I am trying to positions a webview below the gridview on the screen.
Can anyone help explain what I need to do to get that to work?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/HomePage"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridView
android:id="#+id/Grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:scrollbars="vertical" />
<WebView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/webView1" />
</LinearLayout>
</LinearLayout>
Thanks
I think two minor changes will help make this work for you. First, when creating a LinearLayout, the android:orientation attribute is required to indicate whether the children should be added horizontally or vertically. Since you want one view on top of the other, add android:orientation=vertical to the HomePage LinearLayout. Second, your GridView currently has a android:layout_height of fill_parent. This will cause it to expand vertically and fill up the entirety of the LinearLayout, which will keep your WebView from being displayed. Try changing this attribute to wrap_content.
Making the height of both children wrap_content could possibly cause you to have some empty space in your app. If you need either the GridView or WebView to take up all of the empty space in the view, you can use the android:layout_weight attribute. Assign the view you want to expand to fill all remaining space after the rest are drawn the attribute like this: android:layout_weight=1. (Here, the 1 represents 100% of the remaining space) If you want more granular control over what percentage of the parent your children occupy, look into using decimal values with the android:layout_weight attribute or android:weightSum on the parent in conjunction with a android:layout_weight on each of the children. Hope this helps!
Use android:layout_height="wrap_content" in Gridview
Set orientation attribute in inner linear layout.
android:orientation="vertical"
Give fixed height of WebView and set android:layout_weight="" in both child.
Try below code and change according to your webview height and grid view height.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/HomePage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<GridView
android:id="#+id/Grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
android:scrollbars="vertical" />
<WebView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:id="#+id/webView1"
/>
</LinearLayout>
</LinearLayout>
In above code I give Height of WebView 200dp change according to your requirement.