![](/img/trans.png)
[英]Animate an imageview out of the activity and bring a fragment into the activity from the bottom: Android
[英]access the imageview from activity to fragment in android
我必須開發一個Android應用程序。
在這里,我使用片段概念。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/_listDetails"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layout"
>
<ImageView
android:id="@+id/pos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="@+id/neg"
android:src="@drawable/a_pos_off" />
<ImageView
android:id="@+id/neg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="@+id/imageView5"
android:src="@drawable/a_neg_off" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/layout"
android:orientation="horizontal" >
<fragment
android:id="@+id/activity_main"
android:name="com.xmlparsing.MainActivity"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/fragment2"
android:name="com.xmlparsing.SubCate"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
這里我使用了兩個片段 ..它們是。,MainActivity.java和SubCate.java
public class AndroidListFragmentActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment);
}}
這里正面圖像存在於fragment.xml文件中......如果我必須單擊這些正面圖像,這意味着必須增加文本大小以獲得第二個fragement(SubCate.java)的全部內容...
我能怎么做 ??? 請給我這些解決方案......
這是我的第二個片段 (SubCate.java)代碼:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SubCate extends Fragment
{
int count = 0, i, j;
WebSettings webSettings;
WebView fullcontent;
ImageView positive,negative;
AndroidListFragmentActivity _listDetailsFrag;
View activityView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subcate,
container, false);
fullcontent = (WebView) view.findViewById(R.id.fullcontent);
Bundle bundle = getArguments();
return view;
}
public void updateDetail(String articlefullcontent) {
_FullContent = articlefullcontent.substring(1);
fullcontent.setWebChromeClient(new WebChromeClient());
webSettings = fullcontent.getSettings();
fullcontent.getSettings();
fullcontent.loadDataWithBaseURL(null, _FullContent, "text/html", "utf-8", null);
positive = ((ImageView )activityView.findViewById(R.id.pos));
positive.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
count++;
if (count == -1)
{
webSettings.setTextSize(WebSettings.TextSize.SMALLER);
positive.setImageResource(R.drawable.a_pos_off);
negative.setImageResource(R.drawable.a_neg_on);
}
else
if (count == 0)
{
webSettings.setTextSize(WebSettings.TextSize.NORMAL);
positive.setImageResource(R.drawable.a_pos_off);
negative.setImageResource(R.drawable.a_neg_off);
}
else
if (count >= 1)
{ count=1;
webSettings.setTextSize(WebSettings.TextSize.LARGER);
positive.setImageResource(R.drawable.a_pos_on);
negative.setImageResource(R.drawable.a_neg_off);
}
}
});
}
}
我必須運行應用程序並單擊該imageview意味着fullcontent文本不會增加值...我該怎么辦? 請幫幫我,給我一些解決方案???
您的片段找不到相應的ImageView。 編輯到下一個並檢查:
positive = (ImageView )getActivity().findViewById(R.id.pos);//use getActivity() Method
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.