滚动型关上Android应用开放自动滚屏

问题描述 投票:0回答:1

我通过java附加在我的应用程序5个视频播放器。当应用程序打开时,ScrollViewscroll-Y被定位为显示5视频播放器。我怎样才能避免这种情况?我怎样才能关闭自动滚动使应用程序打开时,第一视频播放器出现,scroll-Y为0?

Colors:

<color name="secondary_color">#6CABF7</color>
<color name="light_black">#202125</color>
<color name="dark_black">#0F0F0F</color>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/light_black"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="@color/secondary_color"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="80dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:tag="yo">

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        </LinearLayout>
    </ScrollView>
</android.support.constraint.ConstraintLayout>

MainActivity.java:

package com.example.test;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.*;
import android.view.*;
import android.widget.*;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {
    LinearLayout content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        content = findViewById(R.id.content);

        for (int x=0;x<5;x++) {
            RelativeLayout video_player_box = new RelativeLayout(this);
            RelativeLayout.LayoutParams params;
            VideoView player = new VideoView(this);
            TextView details = new TextView(this);

            LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 600);
            param.setMargins(0,0,0,50);
            video_player_box.setLayoutParams(param);

            params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
            params.setMargins(5,5,5,5);
            player.setLayoutParams(params);
            player.setMediaController(null);
            video_player_box.addView(player);

            params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 50);
            params.setMargins(5,5,5,0);
            details.setLayoutParams(params);
            details.setPadding(15,0,0,0);
            details.setText(Integer.toString(x+1));
            details.setTextSize(25);
            details.setTextColor(getResources().getColor(R.color.dark_black));
            details.setGravity(Gravity.CENTER_VERTICAL);
            video_player_box.addView(details);

            content.addView(video_player_box);
        }
        ((VideoView) ((RelativeLayout) content.getChildAt(0)).getChildAt(0)).setVideoURI(Uri.parse("https://dash.akamaized.net/akamai/bbb/bbb_320x180_60fps_600k.mp4"));
        ((VideoView) ((RelativeLayout) content.getChildAt(0)).getChildAt(0)).start();
    }
}
java android android-scrollview
1个回答
0
投票

粘贴在此对来自右为滚动型的主要子解决了这个问题对我来说我的父母线性布局。 android:descendantFocusability="blocksDescendants

© www.soinside.com 2019 - 2024. All rights reserved.