Я пытаюсь получить всплывающее окно DialogFragment
и показать прокручиваемую легенду TextView
, но она просто отсекает остальную часть легенды. Я не могу прокрутить его или что-то еще. Я попытался добавить ScrollView
, но он ничего не делает. Это экран, который я получаю:Невозможно прокрутить в диалоговом фрагменте
Это мой файл разметки XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:background="#fff">
<TextView
android:id="@+id/layer_legend_title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#fff"
android:textColor="#000" />
<ListView
android:id="@+id/layer_legend_symbols_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="#fff"
android:textColor="#000" />
</LinearLayout>
</ScrollView>
Я бегу, чтобы добавить содержимое в TextView
:
/**
* A dialog that shows the legend of a ArcGISDynamicMapServiceLayer.
*/
public class LegendDialogFragment extends DialogFragment implements View.OnClickListener {
public static final String TAG = LegendDialogFragment.class.getSimpleName();
private LinearLayout mLinearLayout;
private ArcGISDynamicMapServiceLayer mLayer;
private ImageButton backButton;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mLinearLayout = (LinearLayout) inflater.inflate(R.layout.legend_dialog_fragment_layout, null);
getDialog().setTitle(getActivity().getString(R.string.legend));
mLayer = ((MainActivity) getActivity()).getLayer();
backButton = (ImageButton) mLinearLayout.findViewById(R.id.backButton2);
backButton.setOnClickListener(this);
// before we can show the legend we have to fetch the legend info asynchronously
new FetchLegendTask().execute();
return mLinearLayout;
}
public void onAttach(Activity activity) {
super.onAttach(activity);
if (!(activity instanceof MainActivity)) {
throw new IllegalStateException("Hosting activity needs to be of type MainActivity");
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.backButton2:
getDialog().dismiss();
break;
}
}
/**
* Retrieves the legend information asynchronously from the ArcGISDynamicMapServiceLayer.
*/
private class FetchLegendTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
mLayer.retrieveLegendInfo();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for (ArcGISLayerInfo layerInfo : mLayer.getAllLayers()) {
if(layerInfo.isVisible()){
View view = getActivity().getLayoutInflater().inflate(R.layout.layer_legend_layout, null);
populateLegendView(view, layerInfo);
mLinearLayout.addView(view);
}
}
}
private View populateLegendView(View view, ArcGISLayerInfo layerInfo) {
if (layerInfo != null) {
TextView textView = (TextView) view.findViewById(R.id.layer_legend_title_textview);
textView.setText(layerInfo.getName());
}
return view;
}
}
}
Я хочу весь Fragment
можно прокручивать, но не знаю, как этого добиться. Всякий раз, когда я пытаюсь включить ScrollView
, он прокручивает остальную часть этой конкретной строки. Он не покажет весь контент. Я думаю, что это больше связано с DialogFragment
.
EDIT: Хорошо, поэтому я думаю, что знаю, почему он не будет прокручиваться. Он вызывает View
снова и снова в цикле. Затем он заполняет слой и, наконец, добавляет TextView
в LinearLayout
. Таким образом, это не обязательно «прилагается». Поэтому добавление ScrollView
приведет к прокручиванию последней части. Если кто знает, как это исправить, сообщите мне.
Я получил ссылку на пример здесь:
Возможный дубликат [Android - Как сделать это диалоговое окно предупреждений прокручиваемым?] (Http://stackoverflow.com/questions/16955053/android-how-do-i-make-this-alert-dialog- прокручиваемый) – AndroidMechanic
Я не строю его, используя AlertDialog.Builder. Я использую собственный фрагмент диалога. Кроме того, я сделал то, что они сказали, и это не сработало для меня – LAOmeshk
Вы отправили бы код с завернутым scrollviewer? – fillobotto