尝试使用它时,我无法立即运行两个Web视图,但是需要一些帮助……它不像说View2
那样说Swift
一样简单。
布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:background="#ffb067"
tools:context=".FeedFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:text="Feed Fragment" />
<WebView
android:id="@+id/livefeed"
android:layout_width="match_parent"
android:layout_height="310dp"
android:layout_marginTop="200dp" />
<WebView
android:id="@+id/livestream"
android:layout_width="match_parent"
android:layout_height="200dp" >
</WebView>
</FrameLayout>
片段
public class FeedFragment extends Fragment {
private WebView livestream;
private WebView livefeed;
public FeedFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_feed, container, false);
}
@Override
public void onViewCreated(View view , Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
livestream = (WebView) view.findViewById(R.id.livestream);
livestream.setWebViewClient(new WebViewClient());
livestream.loadUrl("website1");
livefeed = (WebView) view.findViewById(R.id.livefeed);
livefeed.setWebViewClient(new WebViewClient());
livefeed.loadUrl("website2");
}
}
一个视图是视频流,另一个是该流的注释。
答案 0 :(得分:0)
您需要使布局可滚动,并将textview的高度更改为wrap_content
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#ffb067"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold"
android:text="Feed Fragment" />
<WebView
android:id="@+id/livefeed"
android:layout_width="match_parent"
android:layout_height="310dp"
android:layout_marginTop="20dp" />
<WebView
android:id="@+id/livestream"
android:layout_width="match_parent"
android:layout_height="200dp" >
</WebView>
</LinearLayout>
</ScrollView>
我强烈建议您阅读Google's a layout。