/ / vytvorenie prekrývajúceho sa textového a webového pohľadu - android, webview, textview

vytvárajú prekrývajúce sa textové a webové zobrazenie - android, webview, textview

Mám rozloženie aplikácie, v ktorom používam webviewako základňa s priečinkom s aktívami obsahujúcim súbory html funguje všetko skvele. to, čo si prajem, je získať dynamický textový pohľad na rovnakom mieste ako webový pohľad štandardne pri spustení aktivity, ale keď užívateľ klikne na tlačidlo, chcem odstrániť textový pohľad a nahradiť ho webovým zobrazením. môže mi niekto pomôcť. vyskúšal spôsob: - Aj keď sa pri vytváraní dvoch podobných rozložení a odozvy používateľa na tlačidlo ďalšie rovnaké rozloženie aktivita otvorí webview. je to zdĺhavé, ale zvládnuteľné mnou.

odpovede:

5 pre odpoveď č. 1

Týmto spôsobom

1) Vytvorte rozloženie „activity_main.xml“

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnChange"
android:text="Show Webview"
android:layout_gravity="right|center_vertical"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="This is Textview.This is Textview.This is Textview.This is Textview.This is Textview.This is Textview.This is Textview.This is Textview.This is Textview." />
</FrameLayout>

</LinearLayout>

2) Vytvorte Javu „MainActivity.java“

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

private WebView webview;
private TextView textView;
private Button btnChange;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("http://www.google.com");
textView = (TextView) findViewById(R.id.textView);
btnChange = (Button) findViewById(R.id.btnChange);

btnChange.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

if (webview.getVisibility() == View.VISIBLE) {
webview.setVisibility(View.GONE);
textView.setVisibility(View.VISIBLE);
btnChange.setText("Show WebView");
} else {
webview.setVisibility(View.VISIBLE);
textView.setVisibility(View.GONE);
btnChange.setText("Show TextView");
}

}
});
}

}

Výkon:

tu zadajte popis obrázku

tu zadajte popis obrázku