我有四个textviews,Linear Layout它们的宽度相等,如下所示,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView86" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题是,文本视图应该以相同的高度显示。该文本视图的内容(文本)将以编程方式设置。我尝试过,Relative layout但widthtextview 的不能相同。我需要高度和宽度都应该与最高的孩子相同。
请指导我。谢谢!
我如何RoomDatabase为我的应用程序进行 VACUUM?我围绕 Room 构建整个应用程序,在某个时刻,一张大表会定期删除,然后再次填充。
我尝试使用查询创建一个额外的 DAO 接口:
@Dao
public interface GenericDao {
@Query("VACUUM")
void vacuum();
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
Error:(13, 10) error: UNKNOWN query type is not supported yet. You can use:SELECT, UPDATE, DELETE
Run Code Online (Sandbox Code Playgroud)
有解决方法吗?
基本上我需要的是,一旦我的表完全清空,自动增量就会再次从 1 开始。
我对数据库设计相当陌生,所以请理解这是否违反最佳实践。是的:我用尽了谷歌和我所知道的所有其他平台。
提前谢谢了!
我正在使用 newsapi.org 中的 api 密钥创建新闻应用程序,这是我使用 https://www.learn2crack.com/2016/02/recyclerview-json-parsing.html上找到的教程创建的接口代码。我很困惑这个接口的语法是什么以及将 api 密钥放在哪里。
公共接口请求接口{
@GET("android/jsonandroid")
Call<JSONResponse> getJSON();}
Run Code Online (Sandbox Code Playgroud)
这是我的 MainActivity.java 代码
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private ArrayList<Article> data;
private DataAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews(){
recyclerView = (RecyclerView)findViewById(R.id.card_recycler_view);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
loadJSON();
}
private void loadJSON(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("BASE_URL")
.addConverterFactory(GsonConverterFactory.create())
.build();
RequestInterface request = retrofit.create(RequestInterface.class);
Call<JSONResponse> call = request.getJSON();
call.enqueue(new Callback<JSONResponse>() {
@Override
public …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了 Android Studio 并在其中创建了一个项目,但是每当我在其中添加 TextView 时,它都没有显示任何内容,即使TextViewAndroid Studio 已经创建的Activity.xml代码也没有显示
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="wrap_content"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="25dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="67dp"
tools:text="Hello World" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
tools:text="sdfsfsfsfs" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Hello World" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
我正在ConstraintLayout在我的应用程序中创建下面的xml。如您所见,我的第一个项目很好,但是在第二个项目中,我的某些部分textView不在屏幕上!
这是我的XML代码:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我知道我可以解决此问题,将以下行添加到textView,但我需要textView做到这一点wrapContent。
app:layout_constraintLeft_toLeftOf="parent"
Run Code Online (Sandbox Code Playgroud)
我对协程suspended在主线程上的内部工作感到好奇。真正的问题是如何suspended在主线程上记录作为协程的函数。究竟在哪里执行死刑?它是虚拟线程吗?
我在RecyclerView. 当我单击列表项启动时BottomSheetDialogFragment。
如何在 kotlin 中将列表项数据传递给 BottomSheetDialogFragment
BottomSheetFragment().show(context!!.supportFragmentManager, "BottomSheetFragment")
class BottomSheetFragment() : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view = inflater.inflate(R.layout.coin_detail_lauout, container, false)
return view
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在尝试学习如何使用RXJava,我想知道如何更改AsyncTask下面的代码并使用RXJava,是否可能。我是新手RXJava,由于AsyncTask已被弃用,我需要一些帮助。
private static class AddTeamAsyncTask extends AsyncTask<Team, Void, Void> {
private TeamDao teamDao;
AddTeamAsyncTask(TeamDao teamDao) {
this.teamDao = teamDao;
}
@Override
protected Void doInBackground(Team... teams) {
teamDao.addTeam(teams[0]);
return null;
}
}
Run Code Online (Sandbox Code Playgroud) <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:elevation="5dp"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/img_delete"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_margin="7dp"
android:src="@drawable/ic_remove"
app:tint="@color/design_default_color_error"
android:tint="@color/white"
/> <!-- Setting tints of Image -->
</LinearLayout>
</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
此代码显示在 ImageView 中添加色调,我想问什么是色调,它的效果在哪里,以及我使用的两种类型的色调之间有什么区别。
这是我添加android:usesCleartextTraffic="true"到AndroidManifest.xml.
Manifest merger failed : Attribute application@usesCleartextTraffic value=(true) from AndroidManifest.xml:29:9-44
is also present at [com.payu.custombrowser:payu-custom-browser:7.5.1] AndroidManifest.xml:17:18-54 value=(false).
Suggestion: add 'tools:replace="android:usesCleartextTraffic"' to <application> element at AndroidManifest.xml:19:5-181:19 to override.
Run Code Online (Sandbox Code Playgroud) android ×10
kotlin ×2
android-room ×1
coroutine ×1
java ×1
performance ×1
retrofit ×1
rx-java2 ×1