A button wont show up - java

I have this xml:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment" >
<ImageView
android:id="#+id/sphereIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/magicBallDescr"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sphereIcon"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtAnswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/launch_codes"
android:layout_width="match_parent"
android:layout_height="106dp"
android:hint="#string/textHint"
android:inputType="text" />
<Button
android:id="#+id/btnAsk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btnAskQ"
/>
</LinearLayout>
</RelativeLayout>
Everything is perfect, but the button won't show up.
What am I missing here? I know that is something basic even for a beginner, but I find it hard to understand as a newbie in the xml world.

Your inner LinearLayout has the orientation 'horizontal'. I guess your view can't show the TextView, EditText and Button in one row. There isn't that much space.

Related

Java Android ScrollView buttons always at the top

Hi I have a ScrollView and inside I have a LinearLayout and inside I have a buttons. I don't know how I can have this buttons always at the top when I scroll a view. Now when I scroll view a buttons disappear.
My code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:weightSum="1">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|bottom"
android:layout_marginTop="0dp">
<Button
android:id="#+id/cpic"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="Zdjęcie" />
<Button
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:text="Wyślij" />
</LinearLayout>
<ImageView
android:id="#+id/Imageprev"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_marginTop="58dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
what I understand from your question i think you can achieve it by putting your button outside your scroll view inside XML , this would give you a fix button.
hope this helps.

Fragments in Android Studio are stacked on top of each other in Virtual Machine

I have to turn my Unit Converter App into fragments and have it working. Everything compiles so I am able to run it in the virtual machine. The only problem is that all of the xml visuals are stacked on top of each other. I will provide code and a picture of what it looks like in my virtual machine. Please help me fix my issue so that they are not stacked on top of each other.
content_unit_converter.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.plamen.unitconverter.UnitConverterActivity"
tools:showIn="#layout/activity_unit_converter">
<fragment
android:id="#+id/unitconverterfragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterFragment"/>
<fragment
android:id="#+id/unitcoverterdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterDisplay"/>
</RelativeLayout>
fragment_unit_converter.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.plamen.unitconverter.UnitConverterActivity"
tools:showIn="#layout/activity_unit_converter">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/TemperatureEditText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Celsius to Farenheit"
android:id="#+id/toFarenheitRadioButton"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Farenheit to Celsius"
android:id="#+id/toCelsiusRadioButton"
android:checked="false" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:id="#+id/convertButton"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner1"
android:spinnerMode="dropdown"
android:layout_below="#+id/LengthEditText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignRight="#+id/LengthEditText"
android:layout_alignEnd="#+id/LengthEditText"
android:entries ="#array/length"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONVERT"
android:id="#+id/convertLength"
android:layout_below="#+id/spinner1"
android:layout_centerHorizontal="true"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner2"
android:layout_below="#+id/AreaEditText"
android:layout_centerHorizontal="true"
android:entries ="#array/area"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:id="#+id/convertArea"
android:layout_below="#+id/spinner2"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
fragment_unit_converter_display.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.plamen.unitconverter.UnitConverterActivity"
tools:showIn="#layout/activity_unit_converter">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/TemperatureEditText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:hint="Enter Temperature" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/LengthEditText"
android:hint="Enter Length"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/AreaEditText"
android:layout_below="#+id/convertLength"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="Enter Area" />
</RelativeLayout>
This is what it looks like when I run it in the Virtual Machine
This is what it looks like after I tried android: layout_below
It is also duplicated which I do not know why.
In general, whenever you use relative layout you must specify where things go. In Linear layout adding a new thing places it below/next to the previous element (depending on your orientation), but in Relative layout this doesn't happen.
So you have this:
<fragment
android:id="#+id/unitconverterfragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterFragment"
/>
<fragment
android:id="#+id/unitcoverterdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterDisplay"
/>
In here you're just displaying 2 fragments but without saying where which one goes first.
You could add this line, or a similar:
android:layout_below="#id/unitconverterfragment"
So now you'll have this:
<fragment
android:id="#+id/unitconverterfragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterFragment"
/>
<fragment
android:id="#+id/unitcoverterdisplay"
android:layout_below="#id/unitconverterfragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.plamen.unitconverter.UnitConverterDisplay"
/>
You can place it below, to the right, left, on top, etc...

ScrollView Does not Scrolll Smoothly

I am adding a ScrollView and several TextView together. I am populating data using a web service (php/mysql data from server). Everything is fine except one issue. When user scrolls the page/activity, the scroll is not as smooth as a listview.
I am posting my xml here:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
android:id="#+id/scrolFullText"
tools:context=".FullText" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/HEAD"
android:text="#string/HEAD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#color/blue"
/>
<TextView
android:id="#+id/WRITER"
android:text="#string/WRITER"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/darkgreen"
/>
<TextView
android:id="#+id/CATEGORY"
android:text="#string/CATEGORY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
/>
<TextView
android:id="#+id/TEXT"
android:text="#string/TEXT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
/>
</LinearLayout>
</ScrollView>
How can I make my scroll a little smoother?
The scroll may be not smooth because some background job is being processed, you may test your app on multiple devices.
By the way I guess the ScrollView height should be match_parent

Why does the GridView keeps resizing iteself?

I am trying to implement a GridView in my Android app, but it seems the GridView keeps resizing. I have attached a video of this below (notice the scrollbar). Although its subtle, but it's really annoying and hampers with parallax scrolling that I am trying to implement.
Video: GridView Issue
Grid Item Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:background="#drawable/card_background"
>
<TextView
android:id = "#+id/foo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="40dp"
style="#style/PrimaryBlueHeading"
/>
<View
android:id="#+id/list_uinderline"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/white"/>
<Button
android:id="#+id/bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:background="#color/brand_color"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:text="#string/save"
android:textColor="#android:color/white" />
</LinearLayout>
GridView Layout:
<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"
tools:context=".ProtocolListActivity">
<!-- android:paddingTop="?android:attr/actionBarSize" -->
<GridView
android:id="#+id/protocol_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:clipToPadding="false"
android:columnWidth="200dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:background="#drawable/backgound_potrait"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:scrollbarStyle="outsideOverlay"
android:gravity="center">
</GridView>
</RelativeLayout>

How to display the Text in bottom of the screen?

In android app i have display the score in TextView in bottom of the screen, It has displayed in emulator but not display in phone. i changed to display in top of the screen it has work in phone
but i need to display in bottom of the screen in phone.
Please any one give idea?
Did you try ALIGN_PARENT_BOTTOM? Note that this will work only in a RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_iphone" >
<TextView
android:id="#+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Here's an example of using RelativeLayout to position text at the top, middle, and bottom of the display.
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Try this code with attribute align_parent_bottom
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>

Categories

Resources