I have an android application. I just added the sample advertisments to my app, and I keep having problems with the ad over my EditText.
When I click on the EditText, the advertisment which is at the bottom of the screen moves up above the keyboard.
My code is below:
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="org.alexwebber.frc.strongholdcalculator.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/autonomous"
android:textSize="25sp"
android:textStyle="bold"
android:layout_alignParentStart="true"
android:id="#+id/autoLabel" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="#+id/autogrid"
android:layout_below="#+id/autoLabel"
android:layout_alignParentStart="true"
android:layout_marginTop="1dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/defreached"
android:id="#+id/defenseReached"
android:textSize="17sp"
android:layout_row="0"
android:layout_column="0"
android:layout_columnSpan="13" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/defcrossed"
android:textSize="17sp"
android:id="#+id/defcrossed"
android:layout_row="1"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/lowgoal"
android:textSize="17sp"
android:id="#+id/lowgoalauto"
android:layout_row="2"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/highgoal"
android:textSize="17sp"
android:id="#+id/highgoalauto"
android:layout_row="3"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/autodefreach"
android:textSize="12sp"
android:layout_row="0"
android:layout_column="24"
android:enabled="true"
android:text="#string/total" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/autodefcross"
android:textSize="12sp"
android:enabled="true"
android:text="#string/total"
android:layout_row="1"
android:layout_column="24" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/autolowgoal"
android:enabled="true"
android:text="#string/total"
android:textSize="12sp"
android:layout_row="2"
android:layout_column="24" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/autohighgoal"
android:textSize="12sp"
android:text="#string/total"
android:enabled="true"
android:layout_row="3"
android:layout_column="24" />
</GridLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teleop"
android:id="#+id/teleopLabel"
android:layout_below="#+id/autogrid"
android:textSize="25sp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_below="#+id/teleopLabel"
android:layout_alignParentStart="true"
android:layout_marginTop="1dp"
android:id="#+id/gridLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/defcrossed"
android:id="#+id/defcrossedtele"
android:textSize="17sp"
android:layout_row="0"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lowgoal"
android:id="#+id/lowgoaltele"
android:textSize="17sp"
android:layout_row="1"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/highgoal"
android:id="#+id/highgoaltele"
android:textSize="17sp"
android:layout_row="2"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/challegedTower"
android:id="#+id/challengestower"
android:textSize="17sp"
android:layout_row="3"
android:layout_column="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scaledTower"
android:id="#+id/scaledtowertele"
android:textSize="17sp"
android:layout_row="4"
android:layout_column="0" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/teledefcross"
android:text="#string/total"
android:enabled="true"
android:layout_row="0"
android:textSize="12sp"
android:layout_column="13" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/telelowgoal"
android:text="#string/total"
android:enabled="true"
android:layout_row="1"
android:textSize="12sp"
android:layout_column="13" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/telehighgoal"
android:text="#string/total"
android:enabled="true"
android:layout_row="2"
android:textSize="12sp"
android:layout_column="13" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/telechallengedtower"
android:text="#string/total"
android:enabled="true"
android:layout_row="3"
android:textSize="12sp"
android:layout_column="13" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/telescaledtower"
android:text="#string/total"
android:enabled="true"
android:layout_row="4"
android:textSize="12sp"
android:layout_column="13" />
</GridLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/gridLayout"
android:id="#+id/rpgrid">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/breach"
android:id="#+id/breach"
android:layout_marginTop="1dp"
android:checked="false"
android:layout_row="0"
android:layout_column="0"
android:layout_below="#+id/gridLayout"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/capture"
android:id="#+id/captured"
android:layout_marginTop="1dp"
android:checked="false"
android:layout_row="0"
android:layout_column="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calculate"
android:id="#+id/button"
android:textSize="20sp"
android:layout_row="1"
android:layout_column="0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/totalscore"
android:textSize="20sp"
android:id="#+id/total"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="right" />
</GridLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:windowSoftInputMode="adjustPan"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
It moves up and overlaps EditText because you set alignParentBottom="true", thus when keyboard shows up, the layout parent bottom is the top of the SoftKeyboard.
You should probably get the solution by adding the all content above the AdView and by calling adjustResize on the Activity declaration in Manifest. On a side note, I'm not sure that calling android:windowSoftInputMode="adjustPan" in AdView xml's widget is going to do something...
Therefore, to handle this behaviour, put the AdView at the top of layout's container and declare a sub-container for the rest of content:
<RelativeLayout ...>
<AdView
android:id="#+id/adView"
android:layout_alignParentBottom="true"
... />
<RelativeLayout
android:layout_above="#id/adView"
...>
<TextView ...>
<GridLayout ...>
<GridLayout ...>
</RelativeLayout>
</RelativeLayout>
Then, make the layout adjusting when keyboard shows up in Manifest.xml:
<activity
android:windowSoftInputMode="adjustResize"
... />
This should work as expected on similar answer. Also, there is another workaround: dynamically detect when the Keyboard is showing up and make the AdView invisible, and vice versa, but I think it does too much hard code than resolved into layout.
Have you set adjustResize for windowSoftInputMode in your Manifest file? this will cause your UI layout to resize when the input method popup. if you don't want to resize, remove it.
<activity
android:name=".TestActivity"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:label="#string/app_name" >
</activity>
http://developer.android.com/training/keyboard-input/visibility.html#Respond
Related
Hi I have a couple of EditText boxes in a GridLayout. However, the code for the EditText is exactly the same. But they look different onFocus event. Any idea why this is occurring?
The texboxes after each one of them were selected:
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:alignmentMode="alignBounds"
android:columnCount="3"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
android:id="#+id/tvDisinfectionContact"
style="#style/formsubsubheader"
android:layout_width="250dp"
android:layout_columnSpan="3"
android:layout_gravity="fill_horizontal"
android:paddingTop="10dp"
android:text="#string/disinfection_contact" />
<TextView
android:layout_width="300dp"
android:layout_columnSpan="1"
android:gravity="start"
android:visibility="gone" />
<TextView
android:id="#+id/tvPpmUnit"
style="#style/fieldlabel"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="#string/unit_ppm" />
<TextView
android:id="#+id/tvMinutesUnits"
style="#style/fieldlabel"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="#string/unit_mins" />
<TextView
android:id="#+id/tvLvlCheAdd"
style="#style/fieldlabel"
android:layout_width="250dp"
android:layout_columnSpan="1"
android:gravity="start"
android:labelFor="#+id/etLvlCheAddPpm"
android:paddingTop="12dp"
android:text="#string/lvl_cheaddition" />
<EditText
android:id="#+id/etLvlCheAddPpm"
android:width="100dp"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:ems="16"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:maxLength="50"/>
<EditText
android:id="#+id/etLvlCheAddMinutes"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:width="100dp"
android:ems="16"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:maxLength="50" />
<TextView
android:id="#+id/tvLvlFlushADD"
style="#style/fieldlabel"
android:layout_width="250dp"
android:layout_columnSpan="1"
android:gravity="start"
android:labelFor="#+id/etLvlFlushAddPpm"
android:paddingTop="12dp"
android:text="#string/lvl_flushddition" />
<EditText
android:id="#+id/etLvlFlushAddPpm"
android:width="100dp"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:ems="16"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:maxLength="50" />
<EditText
android:id="#+id/etLvlFlushMinutes"
android:layout_columnSpan="1"
android:layout_gravity="center_horizontal"
android:width="100dp"
android:ems="16"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:maxLength="50" />
</GridLayout>
On Android O there has been some Input and Navigation Changes . You won't see the changes in the View on different android versions. You can check if your app is running on O, and if so call setDefaultFocusHighlightEnabled(false) on the EditText view.
This sets whether this View should use a default focus highlight when it gets focused but doesn't have R.attr.state_focused defined in its background.
I'm using Android Studio since some weeks. After my first experience I'm building my first APK und have a problem with the Relative layout.
After I'm putting the stuff (ImageBtn, TextView) into it and trying to run the app in the emulator, it shows only the left side.
enter image description here
<?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"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="110dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11"
android:layout_alignTop="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/textView13"
android:layout_alignStart="#+id/textView13" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="190dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_alignStart="#+id/textView14"
android:layout_alignTop="#+id/imageButton7"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_alignStart="#+id/textView15"
android:layout_below="#+id/textView15"
android:text="Level 0"
android:textSize="18sp" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
app:srcCompat="#drawable/pizza"
android:layout_alignTop="#+id/textView11"
android:layout_toRightOf="#+id/textView13"
android:layout_toEndOf="#+id/textView13"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView12"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/imageButton9"
android:layout_toRightOf="#+id/imageButton9"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_below="#+id/textView11"
android:layout_alignLeft="#+id/textView17"
android:layout_alignStart="#+id/textView17" />
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView15"
android:layout_marginLeft="102dp"
android:layout_marginStart="102dp"
android:layout_toEndOf="#+id/textView18"
android:layout_toRightOf="#+id/textView18"
android:text="TextView" />
</RelativeLayout>
Hope you can help me to fix that problem.
Greetings Phil Newman
I will present two ways I would do this if it was me. So you can also choose from this to suit your need.
METHOD ONE
You can use a LinearLayout with vertical orientation as the parent layout.
Use another LinearLayout with horizontal orientation to host a two RelativeLayouts. Each RelativeLayout will also contain the three components(ImageButton, TextViews).
Looks at an xml text I have presented here:
<LinearLayout
android:id="#+id/lay1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton6"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton6"
android:layout_toRightOf="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton6"
android:layout_alignLeft="#+id/textView1"
android:layout_alignStart="#+id/textView1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lay2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton2"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton2"
android:layout_toRightOf="#+id/imageButton2"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView102"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton2"
android:layout_alignLeft="#+id/textView0"
android:layout_alignStart="#+id/textView0" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/pizza" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton3"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton3"
android:layout_toRightOf="#+id/imageButton3"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton3"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3" />
</RelativeLayout>
</LinearLayout>
You can analyse it carefully and just copy and paste depending on the number of buttons(your categories) you want.
METHOD TWO
Arrange everything well in the Relative layout (linearly or preferably a LinearLayout) and put the RelativeLayout in a ScrollView layout as the parent layout. This will enable the user to scroll down and up if the widgets are out of view.
Also here is an xml for that:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="110dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11"
android:layout_alignTop="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<!-- android:layout_marginBottom="7dp" -->
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton6"
android:layout_alignLeft="#+id/textView13"
android:layout_alignStart="#+id/textView13"/>
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="190dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_alignStart="#+id/textView14"
android:layout_alignTop="#+id/imageButton7"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_alignStart="#+id/textView15"
android:layout_below="#+id/textView15"
android:text="Level 0"
android:textSize="18sp" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="270dp"
app:srcCompat="#drawable/pizza" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView16"
android:layout_alignStart="#+id/textView16"
android:layout_alignTop="#+id/imageButton9"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignLeft="#+id/textView17"
android:layout_alignStart="#+id/textView17"
android:layout_below="#+id/textView17" />
</RelativeLayout>
I have 9 Edittext fields to work with. But their is a problem. I set the Edittext fields accordingly but when I run this application on emulator the fields reset them self automatically ( They are not remain at the place where i set them ).And when i run the apk on my mobile (sumsang y S 5360) they look even worse. Here is a Xml code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/zmal"
tools:ignore="ExtraText,TextFields" >
<TextView
android:id="#+id/showz"
android:layout_width="200dip"
android:layout_height="30dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:fontFamily="bold"
android:textColor="#fefdfd"
android:textSize="20sp" />
<Button
android:id="#+id/calc"
android:layout_width="80dip"
android:layout_height="45dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/calbu"
android:paddingBottom="10dp"
android:paddingLeft="5dp" />
<EditText
android:id="#+id/zktmal3"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal2"
android:layout_marginTop="16dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/zktmal5"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal8"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal6"
android:layout_marginTop="27dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal9"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal8"
android:layout_marginTop="21dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp"/>
<EditText
android:id="#+id/zktmal10"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_above="#+id/calc"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:ems="10"
android:padding="3dp"
android:inputType="number"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal1"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal4"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_above="#+id/zktmal5"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal2"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal1"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
<EditText
android:id="#+id/zktmal6"
android:layout_width="40dip"
android:layout_height="20dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/zktmal5"
android:ems="10"
android:inputType="number"
android:padding="3dp"
android:textSize="12sp" />
</RelativeLayout
Here is screenshot
http://postimg.org/image/6yf04lx6h/
Use linearlayout and orientation:horizontal for each row:
And use a general relative layout for scroll view.
like this
<ScroolView>
<RelativeLayout>
<LinearLayout />
<LinearLAyout />
<LinearLayout />
.
.
</RelativeLAyout>
<ScrollView>
You don't show how you layout the TextViews in your XML post but it is clear that they are very verbose. When you have such a long TextView to caption an EditText, it would be better to just put the EditText on the next line.
If I were you, I would just have a scrolling layout like so:
<ScrollView>
<TextView android:id="#+id/label1"/>
<EditText> android:id="#+id/edit1"/>
...
...
<TextView android:id="#+id/labelN"/>
<EditText android:id="#+id/editN"/>
</ScrollView>
I have a textView (titleTv) and an imageView (buyButton) which are sometimes have an overlap if the titleTv has a somewhat long name.
How might this be prevented? I understand this can be done using an external library - but it seems strange there isn't a simple way to accomplish this.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<TextView
android:id="#+id/titleTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="#+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="#color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="#+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:layout_toRightOf="#id/uploaderTv"
android:paddingTop="5dp"
android:textColor="#android:color/black"
android:textSize="16sp" />
<ImageView
android:id="#+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="#drawable/buy_a_up_btn" />
</RelativeLayout>
Example:
(the overlapping fields are the video's title and the $ button)
http://i.stack.imgur.com/clpNv.png
just add your ImageView below that TextView. Add this attribute in your ImageView declaration
android:layout_below="#+id/titleTv"
Now the xml should be like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<TextView
android:id="#+id/titleTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="#+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="#color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="#+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:layout_toRightOf="#id/uploaderTv"
android:paddingTop="5dp"
android:textColor="#android:color/black"
android:textSize="16sp" />
<ImageView
android:id="#+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_below="#+id/titleTv"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="#drawable/buy_a_up_btn" />
</RelativeLayout>
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="7dip"
android:paddingTop="7dip" >
<ImageView
android:id="#+id/buyButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:paddingTop="7dip"
android:src="#drawable/buy_a_up_btn" />
<TextView
android:id="#+id/titleTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/buyButton"
android:background="#color/white"
android:paddingLeft="5dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="#+id/uploaderTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:paddingLeft="5dip"
android:paddingTop="5dp"
android:textColor="#color/verylightgrey"
android:textSize="16sp" />
<TextView
android:id="#+id/viewCountTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/titleTv"
android:layout_toRightOf="#id/uploaderTv"
android:paddingTop="5dp"
android:textColor="#android:color/black"
android:textSize="16sp" />
</RelativeLayout>
I added 11 to 12 column in List view, but I am not able to see all columns. While I scroll list_view will be able to see all columns. Can someone give me ideas how to do this? Here is my XML file code:
ListView Item Xml File
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:scrollbars="vertical" >
<TextView
android:id="#+id/textView1_ID"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView2_Name"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView3_Email"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView4_Mobile"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView5_Products"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView6_Budget"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView7Priority"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView8_Status"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView9_Notes"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView10_Date_Reminder"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView11_Time_Reminder"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView12_AddToContact"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:background="#android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white" />
</TableRow>
</TableLayout>
And here is my ListView Code xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="#string/search_hint" >
<requestFocus />
</EditText>
<ListView
android:id="#+id/listView_DisplayData"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1" >
</ListView>
</RelativeLayout>
You can convert the ListView into a ScrollView and put all your content in there.
Or you create your own ListViewAdapter (or take an existing one such as the ArrayAdapter) and let the adapter insert your data into your listview.
For the latter option, your Activity needs to extend ListActivity and your listview should have the id android.R.id.list.