У меня возникла проблема, когда я пытался использовать метод replace для замены фрагмента для входа на сервер с другим фрагментом карты, но это то, что происходит: новый фрагмент (должен быть фрагментом карты Амазонки) only takes half of the screen. Он должен измениться как новый фрагмент, как только пользователь нажмет кнопку входа (и я тоже попытался изменить фрагмент, но я не смог заставить это работать).Замена фрагментов карт Amazon
В настоящее время я вызываю новый фрагмент из метода onPostExecute задачи Async, который проверяет правильность работы входа. Вот где я называю сделку:
@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();
}
}
Вот файл XML для второго фрагмента, который я звоню:
<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>
Я пытался несколько вещей с изменением этого XML-файл, например как и все перечисленные here, и here, а также, вероятно, почти все перечисленное в документации, предоставленной Amazon, и различные обучающие онлайн.
Я также посмотрел a question for replacing fragments in an Async task, но безрезультатно. Я знаю, что замена работает несколько, как видно из рисунка, который я опубликовал выше, но он, кажется, не охватывает весь экран.
Мои OnCreate и onCreateView для класса карты фрагмента, как следует:
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;
}
Я провел несколько часов возиться с этим кодом и не был в состоянии получить фрагмент карты, чтобы заполнить весь экран - пока отображается карта. Я думаю, что это должно иметь какое-то отношение к моему XML-файлу, так как я смог отобразить его части фрагмента, но не все части там верны. Я думаю, что я правильно делаю замену, и поскольку моя задача Async вложена, замена может работать там просто отлично.
Любая помощь или руководство будет принята с благодарностью! Спасибо огромное!
EDIT
Вот 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>
Что представляет собой XML, где выглядит 'R.id.fragment_login_view'? Также в вашем XML-файле для «Фрагмента карты» 'RelativeLayout', скорее всего, избыточен и может быть удален. – Darwind
@Darwind Я добавил в файл XML для фрагмента входа.Вы правы в RelativeLayout, хотя. Я не знаю, почему у меня это было. Я удалил его из своего кода и повторил его, но у меня все еще такая же проблема. –