I've run into an issue while I've been trying to use the replace method to replace a fragment to log onto a server with another map fragment, but this is what occurs: The new fragment (should be an Amazon map fragment) only takes half of the screen. It should change to be the new fragment once the user hits the sign in button (and I've tried changing the fragment there as well but I haven't been able to get that to work either).
Currently, I'm calling the new fragment from an Async task's onPostExecute method that checks if the login worked properly. Here's where I call the transaction:
@Override
protected void onPostExecute(Boolean result) {
if (result) { //If true, the server tasks were successful
getFragmentManager()
.beginTransaction()
.replace(R.id.fragment_login_view, createFragment())
.commit();
}
}
Here's the XML file for the second fragment that I'm calling:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:amzn_mapType="amzn_normal"
tools:ignore="MissingPrefix"
class="com.amazon.geo.mapsv2.MapFragment" />
</RelativeLayout>
I've tried a number of things with changing this XML file, such as everything listed here, and here, along with probably nearly everything listed in the documentation given by Amazon, and various tutorials online.
I also looked at a question for replacing fragments in an Async task but to no avail. I know that the replace is somewhat working, as can be seen from the picture I posted up above, but it never seems to take up the entire screen.
My onCreate and onCreateView for the map fragment class are as followed:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isAmazonMapsAvailable()){ //this has always been true
Log.i(TAG, "Amazon maps is available!");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_map, container, false);
return v;
}
I've spent several hours messing around with this code and haven't been able to get the map fragment to fill up the whole screen -- while still displaying a map. I think it must have something to do with my XML file, as I've been able to get it parts of the fragment to display, just not all of the pieces are correct there. I think that I'm doing the replace correctly, and since my Async task is nested, the replace is able to work there just fine.
Any help or guidance would be greatly appreciated! Thank you so much!
EDIT
Here's the login_fragment XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_login_view"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@+id/userNameHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_name"
android:paddingTop="25dp"
android:paddingBottom="25dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"/>
<TextView
android:id="@+id/passwordHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password"
android:paddingTop="24dp"
android:paddingBottom="25dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"/>
<TextView
android:id="@+id/serverHostHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_host"
android:paddingTop="24dp"
android:paddingBottom="25dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"/>
<TextView
android:id="@+id/serverPortHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_port"
android:paddingTop="24dp"
android:paddingBottom="25dp"
android:paddingStart="24dp"
android:paddingEnd="24dp"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/userNameEntry"
android:layout_width="150dp"
android:layout_height="match_parent"
android:inputType="text"
android:paddingBottom="22dp"/>
<EditText
android:id="@+id/passwordEntry"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:paddingTop="22dp"
android:paddingBottom="22dp"
android:allowUndo="true"/>
<EditText
android:id="@+id/serverHostEntry"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="text"
android:paddingTop="22dp"
android:paddingBottom="22dp"/>
<EditText
android:id="@+id/serverPortEntry"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:inputType="text"
android:paddingTop="22dp"
android:paddingBottom="22dp"/>
</LinearLayout>
<Button
android:id="@+id/signInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_in"
android:layout_gravity="center_vertical" />
</LinearLayout>