我在我的应用程序中添加了5个视频播放器 java
. 当应用程序打开时 ScrollView
的 scroll-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:
```
<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();
}
}
1条答案
按热度按时间o75abkj41#
将它粘贴到我的父线性布局上,作为scrollview的主子级,解决了这个问题。
android:descendantFocusability="blocksDescendants