Я использую Fragment
внутри Activity
, а ListView
находится внутри моего Fragment
.ListView внутри Фрагмент внутри Activity is not match_parent-ing?
Я установил все на match_parent
, но это работает так, как я не ожидаю.
Пожалуйста, обратитесь к этому изображению для лучшего понимания http://i.imgur.com/2EK6qzs.jpg (не хватают репутаций =. = Не может изображения)
Чтобы сохранить наше время, я опустил большую часть ненужного кода, если я вам понадобится, чтобы обеспечить более коды, пожалуйста, скажите мне.
Спасибо.
activity_book_information.xml
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
...
<!-- Fragments -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/horizontal_line2" />
</RelativeLayout>
fragment_book_review.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button_reviewAddReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bookInfo_addReview"/>
<ListView
android:id="@+id/list_review"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
list_review_single.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_row_curve_rectangle_box">
<!-- Name -->
<TextView
android:id="@+id/book_reviewName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Name"/>
...
</LinearLayout>
Java
BookInformationActivity.java
public class BookInformationActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
setContentView(R.layout.activity_book_information);
f_manager = getFragmentManager();
f_transaction = f_manager.beginTransaction();
f_transaction.replace(R.id.scrollView, new BookReviewFragment(), "f_bookReview");
f_transaction.commit();
}
...
}
BookReviewFragment.java
public class BookReviewFragment extends Fragment {
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
bundle = this.getArguments();
return inflater.inflate(R.layout.fragment_book_review, container, false);
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
list = (ListView) activity.findViewById(R.id.list_review);
new GetReviewTask().execute();
}
public class GetReviewTask extends AsyncTask<Void, Void, Boolean> {
protected void onPreExecute() {
...
}
protected Boolean doInBackground(Void... params) {
...
}
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if(aBoolean != null) {
ListAdapter adapter = new GetReviewAdapter(activity.getApplicationContext(), R.layout.list_review_single, reviewList);
list.setAdapter(adapter); // TODO : Fix Layout issue
}
}
}
}
Опубликовать свою активность_book_information.xml. Вам нужно посмотреть, где находится ваш f_bookReview. – tachyonflux
@tachonflux первый xml является «activity_book_information.xml», f_bookReview - это всего лишь «тег». – user2234894
oh whoops, почему вы используете ScrollView как фрагмент? – tachyonflux