我有扩展View类的MyView类.MyView应绘制填充三角形.我画了一个三角形,但我不能把它填满.这是我的onDraw()方法:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.BLACK);
canvas.drawPaint(paint);
paint.setStrokeWidth(4);
paint.setColor(android.graphics.Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
Point a = new Point(0, 0);
Point b = new Point(0, 100);
Point c = new Point(87, 50);
Path path = new Path();
path.setFillType(FillType.EVEN_ODD);
path.moveTo(a.x, a.y);
path.lineTo(b.x, b.y);
path.moveTo(b.x, b.y);
path.lineTo(c.x, c.y);
path.moveTo(c.x, c.y);
path.lineTo(a.x, a.y);
path.close();
canvas.drawPath(path, paint);
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的结果:

我想将我的LinearLayout集中在ScrollView中.当LinearLayout的高度很小时,它居中(参见图像#1)但是当LinearLayout的高度大于屏幕的高度时,它表现得很奇怪.我看不到LinearLayout的顶部(见图2),ScrollView的底部有巨大的填充.我不知道这里发生了什么.当LinearLayout中有大量内容时,整个屏幕应如图3所示.
Here's my layout file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccfff" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="28dp"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="40dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="40dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tip_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="Title"
android:textColor="@color/orange_text"
android:textSize="@dimen/font_size_medium" />
<TextView
android:id="@+id/tip_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description description..."
android:textSize="@dimen/font_size_small" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 我开始在项目中使用Firebase(Crashlytics)来跟踪应用程序崩溃。它非常适合崩溃,但如何记录非致命崩溃(即捕获的异常)。我试过了,Crashlytics.logException(e)但是没有用。我在仪表板上看不到任何报告。我看到了建议使用的答案,FirebaseCrash.report(t)但最新版本的Firebase中不存在此类。那么有人知道它是怎么做的吗?
依存关系
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'
使用retrofit我想发出POST请求http://milzinas.lt/oauthsilent/authorize.此URL是特殊的,因为它会将您重定向到http://milzinas.e-bros.lt/oauthsilent/authorize.我的改造设置使用OkHttpClient.如果我只使用OkHttpClient发出请求,那么重定向工作正常,即收到401状态代码.但是,当我使用相同的OkHttpClient进行改造时,响应是状态代码307.我认为这与OkClient包装OkHttpClient的实现有关,但我不确定.下面是我用来测试这个场景的代码.我正在使用这些库:
com.squareup.retrofit:retrofit:1.9.0
com.squareup.okhttp:okhttp:2.2.0
Run Code Online (Sandbox Code Playgroud)
据我所知,当URL将您重定向到另一个URL时,http客户端必须发出两个请求.在我的情况下,第一个请求返回307(临时重定向),第二个请求返回401(未授权).但是,改造始终返回第一个请求的响应.你知道如何通过改造使重定向工作正常吗?也许我可以通过使用其他一些HTTP客户端实现这一目标?任何建议将不胜感激.
所以当我执行控制台打印下面的代码
Retrofit failure. Status: 307
OkHttp. Status: 401
Run Code Online (Sandbox Code Playgroud)
我想要它
Retrofit failure. Status: 401
OkHttp. Status: 401
Run Code Online (Sandbox Code Playgroud)
public class MainActivity extends AppCompatActivity {
interface Api {
@POST(URL)
@Headers("Accept: application/json")
void test(@Body Object dummy, Callback<Object> callback);
}
static final String BASE_URL = "http://milzinas.lt";
static final String URL = "/oauthsilent/authorize";
final OkHttpClient okHttpClient = new OkHttpClient();
Api api;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RestAdapter retrofit = new …Run Code Online (Sandbox Code Playgroud) 我有实体类Person,我想从数据库中查询feature可能为也可能不为空的人员。当我将特征设置为非空时,查询有效,但当特征为空时,查询返回空列表。我做错了什么?
测试
Context context = InstrumentationRegistry.getContext();
AppDb db = Room.inMemoryDatabaseBuilder(context, AppDb.class).allowMainThreadQueries().build();
PersonDao dao = db.personDao();
dao.insert(new Person("El Risitas", "Funny"));
dao.insert(new Person("Elon Musk", "Alien"));
dao.insert(new Person("Donald Trump", null));
assertEquals(3, dao.getAll().size());
assertEquals("Funny", dao.getByFeature("Funny").get(0).getFeature());
// fails because dao.getByFeature(null) = EMPTY LIST
assertEquals(null, dao.getByFeature(null).get(0).getFeature());
Run Code Online (Sandbox Code Playgroud)
人.java
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "person")
public class Person {
@ColumnInfo(name = "id") @PrimaryKey(autoGenerate = true) private int id;
@ColumnInfo(name = "name") private String name;
@ColumnInfo(name = "feature") private String feature;
public …Run Code Online (Sandbox Code Playgroud) 我有一个带动作栏的活动.操作栏包含搜索视图.我不希望单击搜索视图时出现的后退按钮.是可以删除它还是隐藏它?在单击搜索视图之前,该后退按钮不可见.顺便说一句,以下代码行没有帮助.
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Run Code Online (Sandbox Code Playgroud)

菜单资源
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:title=""
app:showAsAction="always|collapseActionView"
android:icon="@drawable/ic_action_search"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Run Code Online (Sandbox Code Playgroud) 我有Map<Date, String.我有两个相同的Date对象a, b.我将一个字符串值放到与key关联的地图上a.然后我尝试获取与键相关联的地图值a,b但只a返回我放置的值.是否有可能用b钥匙获得我的价值.我知道当键是简单的字符串时这是可能的.为什么这不适用于其他类型的对象?
public class Main {
public static void main(String[] args) {
Map<Date, String> map = new HashMap<Date, String>();
Date a = new Date(20131105);
Date b = new Date(20131105);
map.put(a, "sweet");
System.out.println(map.get(a));
System.out.println(map.get(b));
}
static class Date {
private int ymd;
public Date(int ymd) {
this.ymd = ymd;
}
public int getYmd() {
return ymd;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof …Run Code Online (Sandbox Code Playgroud) 我有二维点数组,我需要创建一个Path穿过所有点的数组。我想我应该使用Path.cubicTo()使用指定控制点在两点之间创建贝塞尔曲线的方法。问题是我不知道曲线的控制点。我如何计算它们?
也许有更好的方法来做到这一点?也许有某种图书馆可以帮助我?
android ×9
android-room ×1
crashlytics ×1
firebase ×1
hashmap ×1
java ×1
map ×1
multi-window ×1
okhttp ×1
path ×1
retrofit ×1
scrollview ×1
searchview ×1
shape ×1
spline ×1
split-screen ×1