Android布局fill_parent不工作
我想在整个屏幕上进行VideoView拉伸。我在我的项目中的以下布局的xml:Android布局fill_parent不工作
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
tools:context="com.example.myproject.MainActivity"
android:background="@color/green">
<VideoView
android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
然而,在手机屏幕看起来像这样(背景颜色为绿色和宽度不正确拉伸):
而且机器人:
layout_height = “FILL_PARENT” 和
layout_he ight =“match_parent”
产生相同的结果。 手机运行Android 4.4。 此外,使用的主题是Theme.Holo.Light.NoActionBar,但更改主题会产生相同的结果(即使xml预览包含相应的小节)。 我还删除了主要活动中的标题和操作栏。这里是我的MainActivity.java onCreate()方法(这是唯一的事情,我已经改变):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
final VideoView videoPlayer = (VideoView)findViewById(R.id.videoView);
videoPlayer.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.zp);
videoPlayer.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
videoPlayer.start();
return false;
}
});
}
有人能告诉我怎样才能使整个屏幕上的VideoView伸展?
我希望这会帮助你,
<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" >
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这应该工作,虽然fill_parent和match_parent做同样的事情,fill_parent在sdk 8中被重命名为match_parent,所以我们应该只使用match_parent。 – speedynomads 2014-09-02 11:39:43
它的工作原理,值得一提的是关键修改是将LinearLayout更改为RelativeLayout。另外请确保您添加Dhruti发布的行以使其正常工作。 – user2565010 2014-09-02 11:42:56
LinearLayout将视频视图放置在顶部,以便您可以在视频视图下方找到绿色空间,但相关布局会执行您想要的操作。 – RajeshVijayakumar 2014-09-02 11:44:18
你是如何膨胀这样的布局? – laalto 2014-09-02 11:10:03
将android:layout_height =“wrap_content”'更改为'android:layout_height =“match_parent”'怎么样? :) – 2014-09-02 11:10:52
我试着将layout_height更改为“wrap_content”,“match_parent”和“fill_parent”,结果相同。 – user2565010 2014-09-02 11:12:47