所以,我正在尝试在TextView上创建API级别21的循环显示,但我一直收到此错误.起初我认为它与我尝试它的片段的生命周期有关,但后来我在一个活动中尝试了同样的事情,它仍然无法工作.
这是代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window w = getWindow();
w.setFlags(
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
w.setStatusBarColor(Color.parseColor("#0277bd"));
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.text);
int a = (tv.getLeft() + tv.getRight()) / 2;
int b = (tv.getTop() + tv.getBottom()) / 2;
int radius = tv.getWidth();
Animator anim = ViewAnimationUtils.createCircularReveal(tv, a, b, 0, radius);
anim.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
}
Run Code Online (Sandbox Code Playgroud)
现在还很早,所以我真的找不到任何答案.有任何想法吗?
我有一个ScrollView
包含几个RelativeLayouts
,LinearLayouts
像这样:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout >
</RelativeLayout>
<LinearLayout >
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
现在,当我点击其中一个布局时,我希望它能够扩展并显示更多信息.我已经成功地通过以下方式缩放我想要的布局PropertyAnimator
:
relativeLayout.animate().scaleY(100).setDuration(duration).start();
Run Code Online (Sandbox Code Playgroud)
同时,我使用另一个PropertyAnimator
移动Views
到我垂直扩展的那个下方,以便有足够的空间用于扩展布局.到目前为止它正在运作.
不幸的是,Views
那个移动不知何故最终ScrollView
落在了视口之外,所以我无法向下滚动并查看其中的信息Views
.从本质上讲,这些视图的垂直平移使其下部无法访问,因为视口也不会扩展.
我已经开始android:fillViewPort="true"
了ScrollView
.而且我也试图以编程方式进行,setFillViewPort()
但都没有任何影响.
怎么了?为什么不起作用?
我正在更新我的应用程序以使用新的Android Marshmallow权限框架,看起来它足以让用户在运行时授予ACCESS_FINE_LOCATION权限,以使应用程序正常工作.这就是我做的:
public static final String[] runtimePermissions = { permission.ACCESS_FINE_LOCATION };
public static final int LOCATION_PERMISSION_IDENTIFIER = 1;
Run Code Online (Sandbox Code Playgroud)
进一步下课:
public static boolean checkConnectionPermission(final Context context) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
if (context.checkSelfPermission(permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
return true;
}
else {
((Activity) context).requestPermissions(runtimePermissions,
LOCATION_PERMISSION_IDENTIFIER);
return false;
}
}
// since in API levels below M the permission is granted on
// installation,
// it is considered a given that the permission has been granted since
// the
// app is …
Run Code Online (Sandbox Code Playgroud) 我目前正在编写一个连接到服务器以发出POST请求的应用程序.出于这个原因,我为各种网络操作创建了多个Retrofit接口.我有一个执行注册:我接受用户名,电子邮件等,发出POST请求然后作为最后一个参数我有一个回调(RegistrationResult是一个POJO,在类变量中接受"成功"或"失败") .此界面如下所示:
public interface RegistrationInterface {
@FormUrlEncoded
@POST("/api/apiregistration.php")
void connect(@Field("country") String country,
@Field("state") String state, @Field("email") String email,
@Field("pwd") String password,
Callback<RegistrationResult> resp);
}
Run Code Online (Sandbox Code Playgroud)
现在,因为我将使用GCM进行推送通知,所以我有另一个接口将特定设备的注册ID发送到服务器,并再次获得响应.该界面如下所示:
public interface SendRegIDInterface {
@FormUrlEncoded
@POST("/api/apiregid.php")
void connect(@Field("reg_id") String reg_id,
Callback<RegIDResult> resp);
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.当我尝试在同一个类中创建两个接口的实现时出现问题.假设我有一个Activity,由于某种原因,应该使用来自两个接口的实现.所以我有这个:
public class MessageActivity extends Activity implements Callback {
public void onCreate(Bundle firebug) {
RestAdapter restAdapter1 = new RestAdapter.Builder().setEndpoint(endpoint).build();
RegistrationInterface regInter = restAdapter1.create(RegistrationInterface.class);
regInter.connect(// parameters here, MessageActivity.this);
RestAdapter restAdapter2 = new RestAdapter.Builder().setEndpoint(endpoint).build();
SendRegIDInterface regIDInter = restAdapter2.create(SendRegIDInterface.class);
regIDInter.connect(reg_id, MessageActivity.this);
}
@Override
public void …
Run Code Online (Sandbox Code Playgroud) 所以我只是想学习Java,看完一些教程并阅读一些基本的东西后,我不知道为什么这不会运行:
package Test;
public class TestProg {
public static void main(String[] args) {
Fetch fetc = new Fetch();
fetc.more(10, 20);
}
}
Run Code Online (Sandbox Code Playgroud)
这是Fetch类代码:
package Test;
public class Fetch {
public Fetch() {
System.out.println("Fetched!");
int a = 1;
int b = 2;
int c;
while (a < 100 && b < 200) {
a++;
b++;
c = a + b;
System.out.println(c);
}
public void more(int d, int e) {
System.out.println(d + e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个"方法更多(int,int)没有为TestProg中的类型提取"错误定义.如果我删除有关"更多"方法的代码(在两个类中),其余代码将正常运行.我很难过为什么会发生这种情况,因为代码与我正在研究的例子非常相似.
我目前正在开发一个应用程序,它必须每五分钟检查一次用户的位置并将坐标发送到服务器.我决定使用Google Play服务中的FusedLocation API而不是普通的旧BitManager API,主要是因为我注意到了LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY优先级,声称提供100米精度等级且电池使用合理,这正是我需要.
在我的例子中,我有一个Activity,其继承结构是:
public class MainActivity extends AppCompatActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener, LocationListener
Run Code Online (Sandbox Code Playgroud)
并实现相关的回调(onConnected,onConnectionFailed,onConnectionSuspended,onLocationChanged).根据官方文档的建议,我还使用此方法获取了GoogleApiClient的实例:
protected synchronized GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
Run Code Online (Sandbox Code Playgroud)
在onConnected中,我使用启动位置更新
LocationServices.FusedLocationApi.requestLocationUpdates(mApiClient,
mLocationRequest, this);
Run Code Online (Sandbox Code Playgroud)
...并捕获onLocationChanged()中的更改.
但是,我很快发现位置更新似乎在一段时间后停止了.也许是因为这个方法与Activity生命周期有关,我不确定.无论如何,我试图通过创建一个扩展IntentService并由AlarmManager启动的内部类来解决这个问题.所以在onConnected中,我最终做到了这一点:
AlarmManager alarmMan = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
Intent updateIntent = new Intent(this, LocUpService.class);
PendingIntent pIntent = PendingIntent.getService(this, 0, updateIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
alarmMan.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 0,
1000 * 60 * 5, pIntent);
Run Code Online (Sandbox Code Playgroud)
LocUpService类如下所示:
public static class LocUpService extends IntentService {
public LocUpService() {
super("LocUpService");
}
@Override
protected void onHandleIntent(Intent intent) {
Coords …
Run Code Online (Sandbox Code Playgroud)