在ScrollView中使用RecyclerView和CollapsingToolbar

时间:2016-05-02 13:09:21

标签: android android-layout android-recyclerview android-scrollview

我在尝试构建一个包含CollapsingToolbar和Scrollview的布局时出现问题

ScrollView包含两个CardView和一个RecyclerView CollapsingToolbar包含图像,标题和暂时没有按钮

Activity Layout

Content Layout (The ScrollView is missing android:fillViewport="true")

使用这些布局,除了当然滚动之外一切都很好(如果我滚动看起来很烦人,那么视差不会起作用)

这是适配器

public class DetalleActivity extends AppCompatActivity {
final String EXTRA_ITEM = "Complejo";

private TextView txtDireccion;
private ImageView imgThumbnail;
private RecyclerView rvHorarios;

private HorariosAdapter adapter;
public DetalleActivity CustomListView = null;
private Cancha complejoSeleccionado;
private Horario horario;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    complejoSeleccionado = getIntent().getParcelableExtra(EXTRA_ITEM);
    setContentView(R.layout.activity_detalle);
    setToolbar(complejoSeleccionado.getComplejo().toString());

    txtDireccion = (TextView) findViewById(R.id.txtDireccion);
    imgThumbnail = (ImageView) findViewById(R.id.imgThumbnail);

    txtDireccion.setText(complejoSeleccionado.getDireccion());

    String lowerImagen = complejoSeleccionado.getImagen().toLowerCase();
    int idImagen = getResources().getIdentifier(lowerImagen, "drawable", getPackageName());
    imgThumbnail.setImageResource(idImagen);

    rvHorarios = (RecyclerView) findViewById(R.id.rvHorarios);
    rvHorarios.setHasFixedSize(true);

    LinearLayoutManager llm = new LinearLayoutManager(getApplicationContext());
    rvHorarios.setLayoutManager(llm);

    CustomListView = this;

    horario = new Horario();
    horario.initializeData();

    adapter = new HorariosAdapter(horario.horarios);
    rvHorarios.setAdapter(adapter);

    rvHorarios.setNestedScrollingEnabled(false);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_detalle, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    switch (id) {
        case R.id.action_settings:
            return true;
        case R.id.action_search:
            return true;
    }

    return super.onOptionsItemSelected(item);
}

private void setToolbar(String titulo)
{
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (complejoSeleccionado.getComplejo().toString() != null) {toolbar.setTitle(titulo);}

    toolbar.inflateMenu(R.menu.menu_main);
    toolbar.setNavigationIcon(R.drawable.ic_action_arrow);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent a = new Intent(getApplicationContext(), MainActivity.class);
            a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(a);
        }
    });
}

}

在这里我们有活动

Scale.x_log

}

我已经阅读过有关NestedScrollView但我认为它不会解决我的问题 我也试过TouchHandlers,但没有用

问题

如何将所有这三个放在一起并将它们一起滚动?

编辑1:我知道我不应该在ScrollView中使用RecyclerView,可能的解决方案是将它们分隔在不同的标签中?

1 个答案:

答案 0 :(得分:0)