我也有同样的要求Post我跟着FoamyGuy's Answer但我没有得到显示 ImageView 的 introLayout 。
我只想先显示我的 introLayout,然后将其更改为我的 WebView。
这是我的 main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/introLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@color/white"
android:visibility="visible"
>
<ImageView android:layout_width="wrap_content"
android:contentDescription="splash screen"
android:id="@+id/splash"
android:src="@drawable/splash"
android:layout_height="wrap_content"
android:scaleType="centerInside"/>
</RelativeLayout>
<WebView
android:id="@+id/browser"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
/>
</LinearLayout>
在MainActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout introLayout = (RelativeLayout) findViewById(R.id.introLayout);
introLayout.setVisibility(View.GONE);
webview = (WebView)findViewById(R.id.browser);
webview.setVisibility(1);
}
帮忙?
最佳答案
我不知道这是否会有什么不同,但你可以尝试:
webview.setVisibility(View.VISIBLE);
而不是:
webview.setVisibility(1);
PS:使用 View.GONE 使 View 不可见,使用 View.VISIBLE 使 View 可见:)。 只是因为您在 MainActivity 中做了与您描述的相反的事情。
关于java - 在 1 个 Activity 中动态更改布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301351/