Java 显示在中心对齐的web视图 我有一个相对的布局,里面有一个TeXVIEW和一个WebVIEW,我想把两个对象放在屏幕中间的TeVIEW下的WebVIEW,这是我的代码: <?xml version="1.0" encoding="utf-8"?> <FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:background="#FFFFFF" xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="50dp"> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFF" xmlns:app="http://schemas.android.com/apk/res-auto"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="50dp" android:id="@+id/linear" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@null" android:gravity="left" android:paddingLeft="30dp" android:paddingTop="30dp" android:id="@+id/text1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:gravity="left" android:layout_gravity="center" android:paddingLeft="30dp" android:id="@+id/text2" /> <WebView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:gravity="center" android:layout_gravity="center" android:layout_marginLeft="17dp" android:id="@+id/text3"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" app:layout_constraintTop_toTopOf="@id/square2"> <TextView android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:textAlignment="center" android:gravity="center" android:layout_gravity="center" android:layout_marginTop="10dp" /> <WebView android:id="@+id/text6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:background="@null" android:gravity="center" android:layout_gravity="center" android:textAlignment="center"/> </LinearLayout> <ImageView android:layout_width="match_parent" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_height="200dp" app:layout_constraintTop_toBottomOf="@+id/linear" android:id="@+id/square2" android:src="@drawable/square"/> <Button android:id="@+id/text5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="11dp" android:layout_marginRight="11dp" android:layout_marginTop="10dp" app:layout_constraintTop_toBottomOf="@id/square2" android:text="Button" /> </android.support.constraint.ConstraintLayout> </FrameLayout>

Java 显示在中心对齐的web视图 我有一个相对的布局,里面有一个TeXVIEW和一个WebVIEW,我想把两个对象放在屏幕中间的TeVIEW下的WebVIEW,这是我的代码: <?xml version="1.0" encoding="utf-8"?> <FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:background="#FFFFFF" xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="50dp"> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFF" xmlns:app="http://schemas.android.com/apk/res-auto"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="50dp" android:id="@+id/linear" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@null" android:gravity="left" android:paddingLeft="30dp" android:paddingTop="30dp" android:id="@+id/text1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:gravity="left" android:layout_gravity="center" android:paddingLeft="30dp" android:id="@+id/text2" /> <WebView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:gravity="center" android:layout_gravity="center" android:layout_marginLeft="17dp" android:id="@+id/text3"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" app:layout_constraintTop_toTopOf="@id/square2"> <TextView android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:textAlignment="center" android:gravity="center" android:layout_gravity="center" android:layout_marginTop="10dp" /> <WebView android:id="@+id/text6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:background="@null" android:gravity="center" android:layout_gravity="center" android:textAlignment="center"/> </LinearLayout> <ImageView android:layout_width="match_parent" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_height="200dp" app:layout_constraintTop_toBottomOf="@+id/linear" android:id="@+id/square2" android:src="@drawable/square"/> <Button android:id="@+id/text5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="11dp" android:layout_marginRight="11dp" android:layout_marginTop="10dp" app:layout_constraintTop_toBottomOf="@id/square2" android:text="Button" /> </android.support.constraint.ConstraintLayout> </FrameLayout>,java,android,xml,Java,Android,Xml,但是它不起作用,因为webView被放置在左侧,而textView居中,因为它应该看到图像。 我怎样才能修好它?提前谢谢 Web视图未对齐: 如果您计划呈现的html不居中,则无论您如何定位WebView,也不要在WebView上使用wrap\u内容使用match\u父项,否则会使问题更加复杂 在WebView中集中html的唯一方法是 ((WebView) findViewById(R.id.text6)).loadData("<body> <center> Hi &l

但是它不起作用,因为webView被放置在左侧,而textView居中,因为它应该看到图像。 我怎样才能修好它?提前谢谢

Web视图未对齐:


如果您计划呈现的html不居中,则无论您如何定位WebView,也不要在WebView上使用wrap\u内容使用match\u父项,否则会使问题更加复杂

在WebView中集中html的唯一方法是

((WebView) findViewById(R.id.text6)).loadData("<body> <center> Hi </center> </body>", "text/html", "UTF-8");

您的XML在那里有一分钟,您一定已经删除了它。网络视图有一个最高的页边空白。“给你。”塞斯考斯特说done@JeffreyBlattman我已经添加了整个xml,我尝试删除了上边距,但它并没有解决问题。在这里,您正在呈现的网页/html。它从哪里来?@Francescobordinon,我试图理解您的xml。你能提供一张你实际计划做什么的图纸吗?