각 항목이 로컬 HTML 파일 (WebView)을 여는 사용자 지정 ListView가 있습니다. WebView에 대한 ListView 항목을 클릭하면 전환에 애니메이션을 추가하는 데 어려움이 있습니다.ListView 항목이 WebViews로 확대 - 전환 애니메이션
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
String[] values = new String[] { "LINK 1",
"LINK 2", "LINK 3"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (position==0||position==1||position==2) {
view.setBackgroundColor(Color.parseColor("#BBDEFB"));
} else {
view.setBackgroundColor(Color.parseColor("#006064"));
}
return view;
}
};
listView.setAdapter(adapter);
//final HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
**listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
if (position == 0) {
Intent myIntent = new Intent(getApplicationContext(),
WebViewActivity.class);
myIntent.putExtra("key", 0);
startActivity(myIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
}else if (position == 1) {
Intent myIntent = new Intent(getApplicationContext(),
WebViewActivity.class);
myIntent.putExtra("key", 1);
startActivity(myIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle() );
}else if (position == 2) {
Intent myIntent = new Intent(getApplicationContext(),
WebViewActivity.class);
myIntent.putExtra("key", 2);
startActivity(myIntent);
}**
}
});
을하지만 다음과 같은 오류 얻을 :
Error:(69, 60) error: no suitable method found for makeSceneTransitionAnimation(<anonymous OnItemClickListener>)
method ActivityOptions.makeSceneTransitionAnimation(Activity,View,String) is not applicable
(actual and formal argument lists differ in length)
method ActivityOptions.makeSceneTransitionAnimation(Activity,Pair<View,String>...) is not applicable
(actual argument <anonymous OnItemClickListener> cannot be converted to Activity by method invocation conversion)
내 전체 코드 :
을 - 다음과 같이 나는startActivity()
방법에
ActivityOptions.makeSceneTransitionAnimation()
방법을 사용하여 시도
WebViewActivity.java
public class WebViewActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
webView = (WebView) findViewById(R.id.webView1);
//webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
int pos = getIntent().getIntExtra("key", 0);
if (pos == 0) {
webView.loadUrl("file:///android_asset/index.html");
} else if (pos == 1) {
webView.loadUrl("file:///android_asset/index2.html");
} else if (pos == 2) {
webView.loadUrl("file:///android_asset/index3.html");
}
}
}
activity_main.xml
`
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.a405146.listview.MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:background="?android:attr/selectableItemBackground"/>
</RelativeLayout>
`
activity_web_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.a405146.listview.WebViewActivity">
<WebView
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
,745,
제가 잘못 된 곳과 전환을 올바르게 구현하는 방법을 알려주십시오.
감사합니다. 나는이 대답에서 무엇을 바꾸어야하는지에 대한 아이디어를 얻었다! –