Android scrollview width full screen, also Uri.parse(location) - java

i think this question has been asked alot, and yes i have been looking for hours here, nothing really helped me..
I can show the problem with this picture:
http://i.imgur.com/554oMa5.png
sorry that i give link( i don't have enough reputation for image)
As you can see, the width doesn't fit the whole screen..
Trust me, i tried so much things to fix it:
fill_parent
match_parent
gravity=fill
viewport=true
and more..
So here is my XML code for this moment:
<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"
android:background="#000000"
tools:context=".Succes" >
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/google"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickGoogle"
android:text="Go google" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickSudan"
android:text="Go to Sudan!" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickAwesome"
android:text="Awesome button" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="center"
android:text="Rate me!"
/>
<RatingBar
android:id="#+id/lol2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numStars="5"
android:gravity="center" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickHai"
android:text="Hai" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickSuper"
android:text="Super button" />
<View
android:layout_width="fill_parent"
android:layout_height="30dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="onClickOut"
android:text="Go back" />
</LinearLayout>
</ScrollView>
I also have another problem(not connected to first one):
public void onClickSudan(View view)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("GO TO SUDAN?");
dialog.setMessage("Are you really sure go to Sudan?" +
" By pressing yes you will not have the ability to come back!" +
" Please think good before clicking yes(think really good).");
dialog.setCancelable(true);
dialog.setPositiveButton("yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id)
{
//if clicked okay, go to there ;o
Uri location = Uri.parse("geo:18.130191,31.683355");
Intent start = new Intent(Intent.ACTION_VIEW, location);
startActivity(start);
}
});
dialog.setNegativeButton("No.", null);
AlertDialog dialog2 = dialog.create();
dialog2.show();
}
The Uri cannot recognize this coordinates, what is wrong here?
The application crashes.
If the problem is with coordinates so how to get correct coordinates with google maps?
Thanks (:

Two questions, two answers. Your ScrollView is not taking up the entire width of your screen because your top-level RelativeLayout has padding set. Remove the padding attributes and the ScrollView will fit the entire screen. That said, I have no idea why you'd want your ScrollView to take up the entire screen width. Seems like it wouldn't look very nice...

As you can see here, you must prepend your location with "geo:" for it to be a valid URI. You should separate your questions into separate SO posts.

Related

AndroidStudio EditText can't be edited (cursor disappear)

I'm having a weird problem i've never encountered.
I'm building a layout for an activity. My only issue is, i can't edit the edittexts in any way. I've tried both with the emulator and the real device. To be more specific, when i click on the edittext, the cursor appears for a very short moment, then disappears. The keyboard shows up but get stuck and doesn't work. In the java code only enable / disable the the editext :
#Override
public void onClick(View v) {
if(bottlename.isEnabled()){
//bottlenumber.setEnabled(false);
ArrayList<Bottle> bottle = BottleView.getBottlelist();
bottle.set(Integer.parseInt(bottlenumber.getText().toString())-1, new Bottle(bottlename.getText().toString(),Integer.parseInt(bottlenumber.getText().toString()), R.drawable.vodka));
bottlename.setEnabled(false);
}else{
bottlename.setEnabled(true);
//bottlenumber.setEnabled(true);
}
}
});
Any idea what could be the issue?
I've already tried many solutions from other posts, with no luck.
Attaching the xml code here:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/bottleimage"
android:layout_width="150dp"
android:layout_height="160dp" />
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/bottlename"
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#android:color/transparent"
android:enabled="false"
android:focusable="true"
android:gravity="fill_vertical"
android:text="Bottle"
android:textAlignment="center"
android:inputType="text"
android:textSize="36sp"
android:textStyle="bold" />
<EditText
android:id="#+id/bottlenumber"
android:layout_width="match_parent"
android:layout_height="75dp"
android:background="#android:color/transparent"
android:enabled="false"
android:focusable="true"
android:gravity="fill_vertical"
android:inputType="number"
android:text="X"
android:textAlignment="center"
android:textSize="24sp" />
</LinearLayout>
<ImageButton
android:id="#+id/editbottle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:scaleType="center"
android:src="#android:drawable/ic_menu_edit" />
</LinearLayout>
</RelativeLayout>
Is all your EditText fields disabled (android:enabled="false") in your layout intentionally?
the behavior it's a bit weird, I suggest to move the action of reading the value of the editText to a button, so you will have to change the text of the button like this :
When EditTexts enabled ==> "Send"
When EditTexts disabled ==> "Enable"

Trying to open a Pop up window when button is clicked

I'm trying to get a pop-up window (modal window) open when I click a button. I have no idea how it works in Java, I've seen a lot of tutorials and can't figure it out. Here is my button.
<?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:background="#color/white"
>
<LinearLayout
android:layout_margin="50dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_gravity="center"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<Button
//This is the button that should open a modal window
android:id="#+id/btnfruit"
android:background="#mipmap/iconfruit"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="100dp"
android:background="#mipmap/vegetable"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="200dp"
android:background="#mipmap/protein"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="300dp"
android:background="#mipmap/dairy"
android:layout_width="100dp"
android:layout_height="100dp" />
<Button
android:layout_marginTop="400dp"
android:background="#mipmap/grain"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"/>
</RelativeLayout>
this is the modal window.
<?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="400dp"
android:layout_gravity="center"
android:orientation="vertical"
android:padding="5dp"
>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="X"
android:textStyle="bold"
android:layout_gravity="end"
android:gravity="center"/>
<Button
android:id="#+id/btnaddfruit"
android:layout_width="100dp"
android:layout_height="50dp"
android:text="Add Item"/>
</LinearLayout>
I guess my question is, what goes on MainActivity.java or can I code it straight to the button? Thank you in advance for your time and answers.
In whatever class your Button object is in, I would assume MainActivity, create a PopupWindow object (you will have to import the class. Inside of the onClick() method of your button, initialize it and set the location
PopupWindow myWindow = new PopupWindow(View content, int height, int width, true);
myWindow.showAtLocation(View content, Gravity.CENTER, 0, 0);
Obviously you need to fill in the unfilled parameters with your own values.
In order to get the View object needed, you will have to create a new View for the pop up window using a LayoutInflater.

Black Screen Above Elements

I'm having an awkward error, and do not have any clue about what's the cause.
I'm working on a maintenance of an android map application, it was using GoogleMap API, but now I've changed it to MapLink API. One of the view is this one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<EditText
android:id="#+id/searchText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="3dip"
android:ems="10"
android:hint="Busca"
android:maxLines="1"
android:layout_weight="0.85" />
<Button
android:id="#+id/searchBtn"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="#drawable/magnifier13"
android:onClick="search" />
</LinearLayout>
<View
android:id="#+id/separator1"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#color/red" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<br.com.maplink.map.MapTemplate
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</br.com.maplink.map.MapTemplate>
<ImageView
android:id="#+id/drag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/androidpin64"
android:visibility="gone" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dip"
android:orientation="vertical" >
<View
android:id="#+id/separator2"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#color/red" />
<EditText
android:id="#+id/txtEtiqueta"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="3dip"
android:ems="10"
android:hint="Etiqueta"
android:maxLines="1" >
<requestFocus />
</EditText>
<Button
android:onClick="create"
android:id="#+id/btnCadastrarPOI"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:paddingRight="10dip"
android:text="ConcluĂ­do" />
</LinearLayout>
When I click on the top textbox the keyboard just appear and when it's dismissed everything is normal, but when I click on the bottom textbox, the keyboard scroll the content page up and the content above the map goes off the view, when the keyboard is dismissed the content page scrolls back to it's original, but the content above the map is covered by a black frame, if I rotate the device or try to click on the top text box the black frame disappear.
I've already tried to recreate the view on other file but it keep this problem, I've tried the same thing on other project and everything is working fine.
Also, this problem only happen on landscape orientation;
Thanks.

Android/Java: EditText focus moves whole layout, and only ScrollView should be

This phase is supposed to take all basic information and add so-called "Generals", as many as the user wants, but when I click on en "Enter your phone number" EditText, or any of the generals' EditTexts, and the virtual keyboard appears, the whole layout gets pulled up so that the focused EditText can be visible.
Problem is that I need to have the top ribbon containing "Confirm" button available at all occasions. I'm aware of the fact the user can fix that by pressing the Back button, but that'd be extremely unpractical. I need to know how to keep the ribbon up there after everything else gets pulled up by the mentioned EditTexts.
Screenshot of the layout before mentioned EditTexts are tapped:
https://www.mediafire.com/convkey/2da9/4pa1balkda4y4d46g.jpg
Screenshot of the layout after mentioned EditTexts are tapped:
https://www.mediafire.com/convkey/3f9e/so8qq8vud6m3h996g.jpg
Here is layout's XML. "topRibbonLL" LinearLayout should always keep its place at the top, while everything else should be pulled up by tapping the mentioned EditTexts.
<?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="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/topRibbonLL"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/firstDataTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_weight="1"
android:text="Step 3: First data"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/confirmButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="Confirm"
android:onClick="newFileStep3ConfirmPressed" />
</LinearLayout>
<CheckBox
android:id="#+id/shareableCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Other people can share my file" />
<TextView
android:id="#+id/shareableDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:text="Description of the shareableCheckBox effect."
android:textAppearance="?android:attr/textAppearanceSmall" />
<ScrollView
android:id="#+id/dataScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/dataFileName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true" >
</EditText>
<EditText
android:id="#+id/dataFullName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:focusable="true"
android:focusableInTouchMode="true" />
<EditText
android:id="#+id/dataAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPostalAddress"
android:focusable="true"
android:focusableInTouchMode="true" />
<EditText
android:id="#+id/dataPhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:focusable="true"
android:focusableInTouchMode="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Generals:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="#+id/generalsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/newGeneralButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add new general"
android:onClick="newGeneralButtonPressed" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Necessary EditTexts are re-set-up after the layout is opened, so that they'd have grey text etc.
private void setupNewCardEditText(final EditText editText, final String text) {
editText.setTextColor(R.integer.tempTextColor);
editText.setText(text);
editText.setGravity(Gravity.CENTER);
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (editText.getTextColors().getDefaultColor() == R.integer.tempTextColor) {
editText.setTextColor(0xFF000000);
editText.setText("");
}
} else {
if (editText.getText().toString().equals("")) {
editText.setTextColor(R.integer.tempTextColor);
editText.setText(text);
}
}
}
});
}
I solved my problem. I used low-priority threading with a while loop to re-position the ribbon whenever it's not on top and visible. I also had to change the root layout to RelativeLayout to I could have control of the coordinates.

How can i place two buttons side by side with an image at the bottom of the button?

How can i place two buttons side by side with an image at the bottom of the button?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/a_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Button-a" />
<Button
android:id="#+id/b_button"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Button-b" />
</LinearLayout>
Instead of using button u can use linear-layout(Clickable) and use its id instead of Button id.something like this...... Using this you can customize your Button as per your requirements.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
//Button-A
<LinearLayout
android:id="#+id/a_button"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.50"
android:orientation="vertical"
android:clickable="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:text="Text-A"
android:paddingTop="10dip"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/image_A"
android:paddingTop="13dip" />
</LinearLayout>
//For Horizontal partition line
<TextView
android:layout_width="2dp"
android:layout_height="fill_parent"
android:background="#303030"
android:paddingTop="20dip" />
//Button-B
<LinearLayout
android:id="#+id/b_button"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.50"
android:orientation="vertical"
android:clickable="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text-B"
android:gravity="center_horizontal|center_vertical"
android:paddingTop="10dip" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/image_B"
android:paddingTop="13dip"
/>
</LinearLayout>
</LinearLayout>
You can place images at the bottom of buttons with the Drawable_Bottom property.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#android:attr/buttonBarStyle"
android:orientation="horizontal" >
<Button
android:id="#+id/a_button"
style="#android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="#android:drawable/btn_star"
android:text="Button-a" />
<Button
android:id="#+id/b_button"
style="#android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="#android:drawable/btn_star"
android:text="Button-b" />
</LinearLayout>
Just add below line to both your buttons and specify the drawable you want to use.
android:drawableBottom="#drawable/image"
Hope this helps.
EDIT:
Above method works if you want to use your drawables as it is i.e. without modifying its dimensions. If you wish you modify you drawable dimentions as well then you can do that through simple Java code written below:
((Button)findViewById(R.id.button)).setCompoundDrawables(null, null, null, getDrawable(getApplicationContext(), R.drawable.image, 25));
.....
.....
Drawable getDrawable(Context context, int drawable, float form_factor) {
Drawable imgDrawable = context.getResources().getDrawable(drawable);
imgDrawable.setBounds(0, 0, (int)form_factor, (int)form_factor);
return imgDrawable;
}

Categories