Java Android中的循环显示和循环库问题
我是按照教程的“T”,但当我运行的应用程序,我得到以下消息在日志猫。我不确定出了什么问题,因为课堂应该在那里,对吗 找不到从方法io.codetail.animation.ViewAnimationUtils.CreateCircularVeal引用的方法android.view.ViewAnimationUtils.CreateCircularVeal 主要活动:Java Android中的循环显示和循环库问题,java,android,android-view,Java,Android,Android View,我是按照教程的“T”,但当我运行的应用程序,我得到以下消息在日志猫。我不确定出了什么问题,因为课堂应该在那里,对吗 找不到从方法io.codetail.animation.ViewAnimationUtils.CreateCircularVeal引用的方法android.view.ViewAnimationUtils.CreateCircularVeal 主要活动: import android.animation.Animator; import android.animation.A
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.Filter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.curtrostudios.testapp.network.AppConfig;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
/**
* Created by CurTro Studios on 2/22/2016.
*/
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private ProgressDialog dialog=null ;
private String TAG="Main Activity";
private String tag_json_arry = "json_array_req";
private ProductsAdapter adapter;
private ListView list;
ArrayList<ProductRowData> rowdata;
private SearchView searchView;
private MenuItem myActionMenuItem;
LinearLayout mRevealView;
boolean hidden = true;
private ImageButton gallery_btn, photo_btn, video_btn, audio_btn, location_btn, contact_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mRevealView = (LinearLayout) findViewById(R.id.reveal_items);
mRevealView.setVisibility(View.GONE);
gallery_btn = (ImageButton) findViewById(R.id.login_img_btn);
photo_btn = (ImageButton) findViewById(R.id.info_img_btn);
video_btn = (ImageButton) findViewById(R.id.share_img_btn);
audio_btn = (ImageButton) findViewById(R.id.sortAtoZ);
location_btn = (ImageButton) findViewById(R.id.sortDate);
contact_btn = (ImageButton) findViewById(R.id.sortRegion);
gallery_btn.setOnClickListener(this);
photo_btn.setOnClickListener(this);
video_btn.setOnClickListener(this);
audio_btn.setOnClickListener(this);
location_btn.setOnClickListener(this);
contact_btn.setOnClickListener(this);
list=(ListView)findViewById(R.id.productList);
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Get item at position
ProductRowData item = (ProductRowData)parent.getItemAtPosition(position);
//Pass the image title and url to DetailsActivity
Intent intent = new Intent(MainActivity.this, ProductDetail.class);
intent.putExtra("sid", item.getSID());
intent.putExtra("name", item.getName());
intent.putExtra("image", item.getImageURL());
intent.putExtra("thumb", item.getThumbURL());
intent.putExtra("description", item.getDescription());
intent.putExtra("rating", item.getRating());
//Start details activity
startActivity(intent);
}
});
rowdata=new ArrayList<ProductRowData>();
dialog= new ProgressDialog(this);
dialog.setMessage("Loading...");
dialog.show();
JsonArrayRequest request = new JsonArrayRequest(AppConfig.URL_MAIN,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString()); try {
for(int i=0;i<response.length();i++){
String sid=response.getJSONObject(i).getString("sid");
String name=response.getJSONObject(i).getString("product_name");
String img;
String thumb = response.getJSONObject(i).getString("product_thumb");
String description = response.getJSONObject(i).getString("product_description");
String rating = response.getJSONObject(i).getString("product_rating");
img = response.getJSONObject(i).getString("product_pic");
rowdata.add(new ProductRowData(sid,name,img,thumb,description,rating));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
adapter=new ProductsAdapter(MainActivity.this, rowdata);
list.setAdapter(adapter);
dialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " + error.getMessage());
dialog.dismiss();
}
});
VolleyController.getInstance().addToRequestQueue(request, tag_json_arry);
}
@Override
public void onClick(View v) {
hidden = true;
switch (v.getId()) {
case R.id.login_img_btn:
break;
case R.id.info_img_btn:
break;
case R.id.share_img_btn:
break;
case R.id.sortAtoZ:
break;
case R.id.sortDate:
break;
case R.id.sortRegion:
break;
}
}
public void Info(){
Intent info = new Intent(MainActivity.this,
InfoActivity.class);
startActivity(info);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
myActionMenuItem = menu.findItem(R.id.action_search);
searchView = (SearchView) myActionMenuItem.getActionView();
searchView.clearFocus();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
Filter filter = adapter.getFilter();
if (TextUtils.isEmpty(newText)) {
filter.filter("");
} else {
filter.filter(newText);
}
return true;
}
});
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_info:
int cx = (mRevealView.getLeft() + mRevealView.getRight());
// int cy = (mRevealView.getTop() + mRevealView.getBottom())/2;
int cy = mRevealView.getTop();
int radius = Math.max(mRevealView.getWidth(), mRevealView.getHeight());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
SupportAnimator animator =
ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, 0, radius);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(800);
SupportAnimator animator_reverse = animator.reverse();
if (hidden) {
mRevealView.setVisibility(View.VISIBLE);
animator.start();
hidden = false;
} else {
animator_reverse.addListener(new SupportAnimator.AnimatorListener() {
@Override
public void onAnimationStart() {
}
@Override
public void onAnimationEnd() {
mRevealView.setVisibility(View.INVISIBLE);
hidden = true;
}
@Override
public void onAnimationCancel() {
}
@Override
public void onAnimationRepeat() {
}
});
animator_reverse.start();
}
} else {
if (hidden) {
Animator anim = android.view.ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, 0, radius);
mRevealView.setVisibility(View.VISIBLE);
anim.start();
hidden = false;
} else {
Animator anim = android.view.ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, radius, 0);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mRevealView.setVisibility(View.INVISIBLE);
hidden = true;
}
});
anim.start();
}
}
return true;
case android.R.id.home:
supportFinishAfterTransition();
return true;
case R.id.action_search:
return true;
case R.id.action_share:
return true;
}
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
//int id = item.getItemId();
//noinspection SimplifiableIfStatement
//if (id == R.id.action_search) {
// return true;
//}
//if (id == R.id.action_info) {
// return true;
//}
//if(id == R.id.action_share){
// //Share();
// return true;
//}
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
}
编辑
这在我的build.gradle(项目)文件中:
检查导入的库 就我而言
import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
不会出现错误。因为库中明确提到,您应该首先添加远程maven url:
repositories {
maven {
url "https://jitpack.io"
}
}
然后是库依赖项:
compile ('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
transitive = true;
}
现在尝试构建项目并同步渐变!如果这没有帮助,请将aar版本更改为1.1.1
compile ('com.github.ozodrukh:CircularReveal:1.1.1@aar') {
transitive = true;
}
看看是否有帮助
如果问题仍然存在,我建议你阅读博客 虽然,我无法解释为什么会出现错误,因为我还没有尝试过该库,但我认为您可以轻松实现circular reveal,而无需使用上述库。请看一看,它有一个非常简洁的圆形展示工作示例,您可以轻松使用。让我猜猜,您正在一个预棒棒糖设备/模拟器上测试代码(并得到错误) Android在SDK 21(棒棒糖)中引入了类
ViewAnimationUtils
您的minSdkVersion
是16
。看看另一个问题,建议支持库将循环展示动画带回Android 2.3。图书馆在建。您必须使用forkio.codetail.animation.ViewAnimationUtils
才能使用它
编辑:问题并没有提到它已经在使用CircularVeal库——实际上可以从日志中看到
引用自方法
io.codetail.animation.ViewAnimationUtils.CreateCircularVeal
编辑2:在看到更新的响应并从OP知道logcat不是错误而是警告之后
这根本不是问题。这是一个Dalvik
特性,它会检查缺少的类/方法,如果找不到它们,就会发出警告。除非你真的打电话给他们,否则它不会崩溃
OkHttp
库中有类似的警告,您可以看到可以忽略它们
作为旁注,
CircularReveal
库出现在@TargetApi
注释中,它应该使用@SuppressLint(“NewApi”)
@TargetApi
表示您应该仅从该Api级别调用该方法。无论如何,这不是警告的原因,因为此信息仅在编译时可用。对于其他可能看到此问题的人来说,同样问题的“显示动画/菜单”未显示,这就是我解决问题的方法。并不是说展示框架的布局没有显示出来,它只是显示在其他一切的背后。因此,正如您在我下面的布局中所看到的,我刚刚将框架布局移动到所有其他内容的下方,现在它可以完美地工作了
主布局
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.myapp.testapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
//Issue was solved by adding the FrameLayout here.
//below all other content. Works perfectly now.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/reveal_layout" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
//通过在此处添加FrameLayout解决了此问题。
//下面是所有其他内容。现在效果很好。
将gradle文件张贴在此处。@Harshad我将在morning@Harshad请参阅我的编辑尝试删除这个:`compile('com.github.ozodrukh:CircularReveal:1.3)。1@aar“){transitive=true;}`你能添加错误的完整堆栈跟踪吗?是的,我一开始检查并重新检查了这一点,确保了正确的导入。谢谢。在应用程序级别build.gradle中添加远程maven url不在项目级别将maven添加到应用程序级别build.gradle后重试,并将aar更改为1.1.1。仍然获取错误无法从android.view.ViewAnimationUtils类中找到方法CreateCircularVeal,也无法解析静态方法CreateCircularVeal。此库可能有问题!你应该在他们的github中注册这个问题,看看他们是否响应!在发布SO问题之前是否进行了此操作。:/我还尝试了您提供的链接,但仍然出现相同的错误。我尝试了您作为单独的测试项目发布的链接,该链接仅包含“显示”视图,它可以完美地工作,但仍然不适用于我的项目:(我的设备正在运行4.4.2。在他的回答中,我从Ishwors链接运行了一个单独的项目,它运行得很好。logcat不再向我提供有关该问题的详细信息。在同一设备上运行的单独测试项目给出了相同的logcat消息,但仍然有效。:/我将min api更改为15,但仍然看不到动画/显示。有什么想法吗?)这可能是由t引起的?您问的是为什么会出现该警告,而不是为什么它不会产生动画
compile ('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
transitive = true;
}
compile ('com.github.ozodrukh:CircularReveal:1.1.1@aar') {
transitive = true;
}
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.myapp.testapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
//Issue was solved by adding the FrameLayout here.
//below all other content. Works perfectly now.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/reveal_layout" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>