package gfxy.com.fragment_dahb;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Web extends Fragment {
WebView we;
EditText ed1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.web,null);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().setContentView(R.layout.web);
Button bu = (Button) getActivity().findViewById(R.id.webbut);
ed1 = (EditText) getActivity().findViewById(R.id.webed);
we = (WebView) getActivity().findViewById(R.id.webweb);
WebSettings wes = we.getSettings();
wes.setJavaScriptEnabled(true);
bu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setweb();
}
});
we.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
Toast.makeText(getActivity(), "網頁加載完成", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "加載中", Toast.LENGTH_SHORT).show();
}
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && we.canGoBack()){
we.goBack();
return true;
}
return false;
}
public void setweb() {
we.loadUrl("http://" + ed1.getText().toString().trim());
we.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
}
package gfxy.com.fragment_dahb;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
/**
* Created by Administrator on 2016/4/18.
*/
public class bt extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FrameLayout sa = (FrameLayout) getActivity().findViewById(R.id.fm);
sa.removeAllViews();
CategorySeries dataset=buildCategoryDataset("測試餅圖");
GraphicalView graphicalView=ChartFactory.getPieChartView(getActivity(),dataset, renderer);//餅狀圖
sa.addView(graphicalView, new RadioGroup.LayoutParams(RadioGroup.LayoutParams.FILL_PARENT, RadioGroup.LayoutParams.FILL_PARENT));
}
protected CategorySeries buildCategoryDataset(String title) {
CategorySeries categorySeries = new CategorySeries(title);
categorySeries.add("勝 ", 30);
categorySeries.add("負", 20);
categorySeries.add("平", 50);
return categorySeries;
}
int[] colors={Color.BLUE,Color.GREEN,Color.MAGENTA,Color.RED};
DefaultRenderer renderer=buildCategoryRenderer(colors);
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
renderer.setLegendTextSize(20);//設置左下角表注的文字大小
//renderer.setZoomButtonsVisible(true);//設置顯示放大縮小按鈕
renderer.setZoomEnabled(false);//設置不允許放大縮小.
renderer.setChartTitleTextSize(30);//設置圖表標題的文字大小
renderer.setChartTitle("統計結果");//設置圖表的標題 默認是居中頂部顯示
renderer.setLabelsTextSize(20);//餅圖上標記文字的字體大小
//renderer.setLabelsColor(Color.WHITE);//餅圖上標記文字的顏色
renderer.setPanEnabled(false);//設置是否可以平移
//renderer.setDisplayValues(true);//是否顯示值
renderer.setClickEnabled(true);//設置是否可以被點擊
renderer.setMargins(new int[]{20, 30, 15, 0});
//margins - an array containing the margin size values, in this order: top, left, bottom, right
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="sadsd"
android:textSize="25dp"
android:gravity="center"
android:background="#0f4"/>
</LinearLayout>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@null"
android:choiceMode="singleChoice">
</ListView>
<FrameLayout
android:id="@+id/fm"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
我想把Web。和bt顯示在framelayout裡面,求教怎麼做?
還有ListView的點擊跳轉事件之前用還沒問題,也不知道干了什麼,然後就不能進行跳轉了
求解決??
package gfxy.com.fragment_dahb;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends Activity {
private String[] name = new String[]{
"餅圖","靜態折線","動態折線","Web","逐幀動畫","縮放,透明,旋轉,平移"
};
private FragmentManager fm;
private FragmentTransaction ft;
private FrameLayout fml;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fml = (FrameLayout) findViewById(R.id.fm);
ListView lv = (ListView)findViewById(R.id.lv);
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
for (int i=0;i<name.length;i++){
Map<String,Object> map = new HashMap<String,Object>();
map.put("name",name[i]);
list.add(map);
}
lv.setAdapter(new SimpleAdapter(this,list,R.layout.content_main,new String[]{"name"},new int[]{R.id.text1}));
// int wi = getWindowManager().getDefaultDisplay().getWidth();//獲取手機寬度
// int hi = getWindowManager().getDefaultDisplay().getHeight();//獲取手機高度
fm = getFragmentManager();//創建一個Fragment
ft = fm.beginTransaction();//對Fragment進行添加,刪除,替換
ft.replace(R.id.fm,new Fragment1());
ft.commit();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
ft = fm.beginTransaction();
ft.replace(R.id.fm,new bt());
ft.commit();
}
if(position==1){
ft = fm.beginTransaction();
ft.replace(R.id.fm,new Fragment1());
ft.commit();
}
if(position==3){
ft = fm.beginTransaction();
ft.replace(R.id.fm,new Web());
ft.commit();
}
}
});
}
}
底部導航欄點擊跳轉fragment
----------------------biu~biu~biu~~~在下問答機器人小D,這是我依靠自己的聰明才智給出的答案,如果不正確,你來咬我啊!