There is a list of comments under the header, they should be in the ScrollView and occupy the entire space below the header. Also under the heading there is another heading, but it is smaller and it should scroll along with the list of comments !!!
But for some reason, comments do not take up all the free space and the subtitle does not scroll.
Here is my code:
Comment item layout:
<?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" android:background="@color/colorLight" > <Button android:id="@+id/coment_avatar_round" android:layout_width="@dimen/circle_radius" android:layout_height="@dimen/circle_radius" android:background="@drawable/rounded" android:textColor="@android:color/white" android:textSize="@dimen/text_midle_size" android:layout_margin="@dimen/activity_vertical_margin" android:padding="@dimen/inner_padding" android:text="N" /> <TextView android:id="@+id/coment_text" android:layout_width="match_parent" android:layout_toRightOf="@id/coment_avatar_round" android:layout_height="wrap_content" android:padding="@dimen/inner_padding" android:textColor="@color/colorPrimaryDark" android:layout_margin="@dimen/activity_vertical_margin" android:text="coment" /> </RelativeLayout> ListFragment class for this layout
public class ComentsViewFragment extends ListFragment { ArrayList<ComentInflater> comentInflaters = new ArrayList<>(); String text = "vvvvvvvvvvvvvvv" + "vvvvvvvvvvvv" + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" + "vvvvvvvvvvvvvvvvvvv " + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" + "vvvvvvvvvvvvvvvvvvvvvvvv gggggggggggggg" + " gggggggggggggg " + "gggggggggggggg" ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); comentInflaters.add(new ComentInflater("#ff3d00", "A", text)); comentInflaters.add(new ComentInflater("#ff3d00", "V", text)); comentInflaters.add(new ComentInflater("#ff3d00", "D" , text)); comentInflaters.add(new ComentInflater("#ff3d00", "O" , text)); comentInflaters.add(new ComentInflater("#ff3d00", "M" , text)); comentInflaters.add(new ComentInflater("#ff3d00", "K" , text)); comentInflaters.add(new ComentInflater("#ff3d00", "L" , text)); ComentAdapter comentAdapter = new ComentAdapter(comentInflaters); setListAdapter(comentAdapter); } private class ComentAdapter extends ArrayAdapter<ComentInflater>{ public ComentAdapter(ArrayList<ComentInflater> coment){ super(getActivity(), 0, coment); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null){ convertView = getActivity().getLayoutInflater().inflate(R.layout.coments_layout, null); } ComentInflater c = getItem(position); Button avatarButton = (Button) convertView.findViewById(R.id.coment_avatar_round); avatarButton.setText(c.getLetter()); TextView textComent = (TextView) convertView.findViewById(R.id.coment_text); textComent.setText(c.getText()); return convertView; } } } Then I put this fragment on the main activit:
layout activation
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="90dp" android:background="@android:color/holo_blue_dark" /> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/colorPrimary"> <FrameLayout android:id="@+id/sub_el" android:layout_width="match_parent" android:layout_height="55dp"/> <FrameLayout android:id="@+id/test_croll_conteiner" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> </LinearLayout> Activity class:
public class TestScroll extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_scroll_activity); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.test_croll_conteiner, new ComentsViewFragment()) ; fragmentTransaction.commit(); } } As a result, comments are scrolled, but they take up space equal to one comment, that is, do not fill free space with weight! And the subtitle does not scroll at all !!
Blue is a cap, under it is a “subtitle”, under it is my sheet, and the gray area (this whole area should be occupied by a sheet) is scrolling!
How to fix it ?? Or do it right?
