I am unable to see anything (the textviews) after building the app.
Only the background image is showing up and nothing else.Tried everything but still the texts doesn't show up.
Under the scrollview i make a linear layout and under that there are several other textviews.But none of them are actually showing up when i am building the app.
How can i make everything under the scrollview visible?
Here's my code:
`
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/blck"
android:weightSum="1"
tools:context="com.gnulinuxusersgroup.nitdgp.glug.faqs"
app:layout_collapseParallaxMultiplier="1.0">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="75dp"
android:id="#+id/F"
tools:text="#string/faq"
tools:textColor="#ffffff"
tools:textSize="100px"
android:textAppearance="#style/TextAppearance.AppCompat"
android:layout_weight="0.02" />
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
tools:text="#string/hwr"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="300px"
tools:text="### `string/hwr2"
tools:textColor="#fff"
tools:textSize="40px"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
tools:text="#string/foss"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="269dp"
tools:text="#string/foss2"
tools:textColor="#fff"
tools:textSize="40px" />
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
tools:text="#string/work1"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="300px"
tools:text="#string/work2"
tools:textColor="#fff"
tools:textSize="40px"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
tools:text="#string/free"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="300px"
tools:text="#string/free2"
tools:textColor="#fff"
tools:textSize="40px"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="46dp"
tools:text="#string/git"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="300px"
tools:text="#string/git2"
tools:textColor="#fff"
tools:textSize="40px"
/>
<TextView
android:layout_width="394dp"
android:layout_height="50dp"
tools:text="#string/gsoc"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="700px"
tools:text="#string/gsoc2"
tools:textColor="#fff"
tools:textSize="40px"
/>
</LinearLayout>
</ScrollView>
`
Replace your various tools: attributes with android: attributes.
The tools namespace is used only by the Android Studio design preview window. This allows you to do things like specify placeholder text so that you can see what it would look like... without specifyiing actual user-visible text that might incorrectly appear in the real world.
Take this TextView:
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
tools:text="#string/hwr"
tools:textColor="#fff"
tools:textSize="40px"
tools:textStyle="bold"
/>
Because all of the last four attributes use the tools namespace, they will not actually have any effect when you run the app. This is the same as having written this (as far as your running app is concerned):
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
/>
For now, just replace all the tools namespaces with android:
<TextView
android:layout_width="match_parent"
android:layout_height="130px"
android:text="#string/hwr"
android:textColor="#fff"
android:textSize="40px"
android:textStyle="bold"
/>
Adding to the Ben P's answer, the possible culprits are:
Check your background color as you are setting text color to white make sure they have contrast.
As the orientation of LinearLayout is Vertical and you are using weight sum its better to have layout_height="0dp" in case of horizontal orientation have width as 0dp.
If you are specifying weightsum make sure the layout_weight adds up to the value, you can omit the weightsum by which system calculates percentages automatically by considering individual weights of widgets in group.
Also as the widgets are textview you can't see much difference in vertical orientation so i have changed the below xml orientation to horizontal so that while running on device or in the layout preview window you can see the weight difference clearly.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/F"
android:text="hello1"
android:textSize="60px"
android:textAppearance="#style/TextAppearance.AppCompat"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello1r"
android:textSize="40px"
android:textStyle="bold"
android:layout_weight="4"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello3"
android:layout_weight="1"
android:textSize="40px"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello4"
android:layout_weight="2"
android:textSize="40px"
android:textStyle="bold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="hello5"
android:textSize="40px" />
Related
How can I make a fixed portion of a scroll activity display on every screen size?
I have a scrollable activity which contains a pageviewer, and below that, 4 buttons. On an average screen it just displays only these things, the rest comes below the screen, which means there are few more views below the button. If we use a wider screen, then these views also appear in main view before scrolling. I need to make the view range the same for all screen sizes, meaning for wider screen also, I need to just view the pageviewer and buttons only, the rest should be seen only when we scroll.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/idd_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="500dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button1" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="other view" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="other view" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="other view" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="other view" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="other view" />
</LinearLayout>
</ScrollView>
</LinearLayout>
set ViewPager height programatically so it can match mobile height
I am busy designing my first app in android but I am having some problems.
I have created this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mfr.calculatorapp.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_margin="15dp"
android:text="123"
android:id="#+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/number_button_size"
android:textSize="#dimen/number_button_size"
android:layout_margin="10dp"
android:text="1"
android:id="#+id/button_1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/number_button_size"
android:textSize="#dimen/number_button_size"
android:layout_margin="10dp"
android:text="1"
android:id="#+id/button_1" />
</LinearLayout>
But the two Buttons appear underneath each other and not on top of each other, I know that if I change orientation to horizontal that I will be able to position it next to each other but I want to be able to span a textview over the top.
What do I do?
Regards
Matt
You will want to use a relative layout. You will see the below code didn't need a lot of extra attributes to pull this off.
Notice that the buttons now have three additional attributes.
andoid:layout_below="#id/" : positions the element under another element
android:layout_alignWithParentIfMissing : if the above mentioned element is not present, align with the parent
android:layout_alignParentLeft : allows you to position one button to the left and one to the right
UPDATE use android:layout_alignRight="#id/textView" to properly align your second button to the right
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mfr.calculatorapp.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_margin="15dp"
android:text="123"
android:id="#+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/number_button_size"
android:textSize="#dimen/number_button_size"
android:layout_margin="10dp"
android:text="1"
android:id="#+id/button_1"
android:layout_below="#id/textView"
android:layout_alignWithParentIfMissing="true"
android:alignParentLeft="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/number_button_size"
android:textSize="#dimen/number_button_size"
android:layout_margin="10dp"
android:text="2"
android:id="#+id/button_2"
android:layout_below="#id/textView"
android:layout_alignWithParentIfMissing="true"
android:alignParentRight="true"
android:layout_alignRight="#id/textView"
/>
</RelativeLayout>
I have a lot of info to put on one xml page. Now i got what I want in the positions i want. However instead of fitting all my data on 3 key parts without running into each other, It keeps running into the next TextView. I was wondering how to have it auto adjust.
<?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:orientation="vertical" >
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/back" />
<TextView
android:id="#+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginTop="97dp"
android:text="#string/part_section_2" />
<TextView
android:id="#+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="#+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_makeup"
android:layout_below="#+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="#+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="#string/part_section_1" />
<TextView
android:id="#+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/part_info"
android:layout_below="#+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="#+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/part_makeup"
android:layout_marginTop="48dp"
android:text="#string/part_section_3" />
<TextView
android:id="#+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
would ScrollView work better? and how would switch this from this to ScrollView.
skin is 480x800
density is high(240)
Strings file - http://pastie.org/8534713
Changing to ScrollView (source):
<?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"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
Edit:
As well as that, try changing your back button XML to this:
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="#string/back" />
The problem was android:layout_alignParentBottom="true". The bottom ended up not going to the bottom of the page like you had before. The ScrollView cut back on the bottom of the layout.
I have created a widget. I intentionally used layout_weight
so it would fit any screen size.
The widget is always spanned to 1X4.
I now look at different devices in the graphic editor and I see the weight doesn't help.
should I move to dip size?
The linear-layouts are spanned differently in relation to the background image.
My XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/app_widget_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/widget_bg_main"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="0dp" >
<RelativeLayout
android:id="#+id/layout_status_image"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="0.21"
>
<ImageView
android:id="#+id/image_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/widget_icon_no_data"
android:visibility="invisible" />
<!--
Layout is necessary because the setVisibility of ProgressBar is not working
through remote views in 2.1. So wrapped by this layout
-->
<FrameLayout
android:id="#+android:id/widget_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="1dp" >
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="39dp"
android:layout_height="39dp"
android:indeterminateOnly="true"
android:orientation="vertical" />
</FrameLayout>
</RelativeLayout> <!-- Status image layout -->
<!--
========================================================================
* Information layout - contains all the texts
========================================================================
-->
<LinearLayout
android:id="#+id/layout_information"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:layout_weight="0.56"
>
<TextView
android:id="#+id/text_view_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="\# Home in"
android:textColor="#color/solid_white"
android:textSize="19sp"
android:textStyle="bold"
android:layout_gravity="left"
/>
<TextView
android:id="#+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#color/solid_white"
android:textSize="25sp"
android:textStyle="normal"
android:layout_gravity="left"
/>
</LinearLayout> <!-- Information layout -->
<!--
========================================================================
* Action layout - action buttons container
========================================================================
-->
<LinearLayout
android:id="#+id/layout_action"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="0.23"
>
<ImageView
android:id="#+id/image_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/widget_bt_drive_disabled" />
<TextView
android:id="#+id/text_view_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Drive!"
android:textColor="#color/disabled_white"
android:textSize="15sp"
android:textStyle="bold"
android:layout_gravity="center"
/>
</LinearLayout> <!-- Action layout -->
It is obvious because single layout working perfectly on a normal screen sized device doesn't mean that it'll work the same way on large/xlarge sized screens. So create a folder inside res "layout-large" or "layout-xlarge" (depending on device screen size). Copy same layout into newly created folder and then make some changes to it, so it'll fit for large/xlarge screens as per your requirement. Also you may copy images into ldpi, mdpi, hdpi and xhdpi to support multiple densities.
For more info: http://developer.android.com/guide/practices/screens_support.html
Hope this helps.
Do android:layout_...s work with ImageViews? From the picture you can see that all 10 rows are on top of each other so that means that q2Image is not accepting the code android:layout_below="#/q1Image" for it to drop down a line and star the next row.
Am I just missing something or am I trying to do something that is impossible?
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="65"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/q1Image"
android:layout_width="10dp"
android:layout_height="10dp" />
<TextView
android:id="#+id/q1Question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q1Image" />
<TextView
android:id="#+id/q1Answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q1Question" />
<TextView
android:id="#+id/q1Verse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q1Answer" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#C2BEBF" />
<ImageView
android:id="#+id/q2Image"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_below="#id/q1Image" />
<TextView
android:id="#+id/q2Question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q2Image" />
<TextView
android:id="#+id/q2Answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q2Question" />
<TextView
android:id="#+id/q2Verse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/q2Answer" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#C2BEBF" />
//Above code is first 2 rows. There are 10 rows total but I removed the code for rows 3-10 for this post.
Try to put + between # and id and everything must be ok
#+id
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- here the columns -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<!-- here the columns -->
</LinearLayout>
.
.
</LinearLayout>
Referencing Id's like that not always working. Replace "#id" with "#+id" everywhere.
Example:
android:layout_below="#+id/q1Image"
The way you are accessing the ids in the code is correct. "#+id" is used to declare the id. All references to it following the declaration should be "#id". Are you having the same problems with the TextViews also? I think you should set the layout_below property for the TextViews as well. Because I can see text is also overlapped in your UI. eg.,
<TextView
android:id="#+id/q2Question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below = "#id/q1Question"
android:layout_toRightOf="#id/q2Image" />
RelativeLayout will not place a view below another unless you specify layout_below for it. Hence your TextViews appear overlapped.