我在XML文件中.我想在这里被得到它的ID.但应用力closes.whats错误的设置按钮上的文本定义.我为我的按钮布局这个Android的代码?
package com.action ;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class ActionActivity extends Activity {
@Override
public void onCreate(Bundle i){
super.onCreate(i);
Button button=(Button) findViewById(R.id.but);
button.setText("Hey!!");
setContentView(R.layout.main);
}
}
Run Code Online (Sandbox Code Playgroud)
日Thnx ...
我有一个应用程序,可以显示数据库中的某些内容并允许用户对其进行编辑。我有一个活动在一些文本视图中显示这些详细信息。现在,屏幕底部有一个“编辑”按钮。单击此按钮时,我想让文本视图可编辑(最初是只读的),以便可以更新数据库。另外,我希望“编辑”按钮变成“保存”按钮。我知道我可以使用另一个活动来实现此目的,但是有什么方法可以在同一个活动中执行此操作吗?
我有一个正在创建的应用程序。我想让这个应用程序支持平板电脑,所以我在我的 res: 中创建了一个文件夹res/layout-xlarge/my_layout.xml。但是,当我在平板电脑(定义为 7 英寸或以上)上运行我的应用程序时,布局不是从layout-xlarge文件夹中使用,而是从layout文件夹中使用。
然后我发现还有一些layout-large我也可以使用的布局。我还没有尝试过,但我会的。
我想知道layout文件、layout-large文件和layout-xlarge文件之间有什么区别。哪一种最适合用于平板电脑布局?
谢谢!
我正在尝试通过从 android studio 中删除未使用的 xml 和 java 代码来优化我的 android 项目,并且我正在寻找这样的快捷方式,这可以帮助我实现优化。
提前致谢。
optimization android android-xml android-resources android-studio
What is the difference between these three xml files in android?
xml file with selector as root element
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<Further Designing ... />
...
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
xml file with shape as root element
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<Further Designing ... />
...
</shape>
Run Code Online (Sandbox Code Playgroud)
xml file with layer-list as root element
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<Further Designing ... />
...
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<Further …Run Code Online (Sandbox Code Playgroud) 我试图让我的TextView宽度具有动态宽度并ImageView固定在它的末端,在ConstraintLayout. 当文本很长时,我想使用省略号并将其ImageView固定在其右侧的视图上。
这是我试图在视觉上实现的目标的示例:
使用我的代码,我能够获得第一张图像,thisIsShortText但是当我有长文本时,它看起来很糟糕,如下所示:
和只是向右延伸到无穷大TextView。ImageView谁能帮我解决这个问题吗?这是我的 XML 代码。如果你只是将它放入你的 Android Studio 中,它看起来就像我的图像。谢谢你:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="70dp">
<!-- This view does not move or change size. -->
<View
android:id="@+id/firstView"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@android:color/holo_red_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</View>
<!-- This view's width is dynamic and changes size based on it's text length.
If the length of text is too long to fit, it uses an …Run Code Online (Sandbox Code Playgroud) android textview android-layout android-xml android-constraintlayout
我正在为非常有限的硬件开发一个应用程序,并决定使用 jetpack compose。
当我需要显示卡片列表并且用于它的惰性行变得非常滞后时,问题就出现了。为了进行比较,我选择了一个带有 recyclerView 的示例项目,并用它来显示大致相同的卡片列表,并且滚动尽可能平滑。jetpack compose 本质上比 xml view 慢还是我做错了什么?
撰写代码(我无法准确分享我的代码,但可组合的卡片只是一张带有一些图像、图标和文本的卡片):
@Composable
fun mainComposable(){
...
cardList = remember{ arrayListOf(...) }
lazyList(cardList)
...
}
@Composable
fun lazyList(
cardList: List<CardContent>,
){
LazyRow(
horizontalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(horizontal = 32.dp)
) {
items(
items = cardList,
key = { it.id }) { item ->
CardComposable(
content = item
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经花了一些时间搜索,所以我发现了很多优化,比如在发布模式下运行,在 build.gradle 上将 minifyEnabled 和收缩资源设置为 true,在 gradle.properties 中将 android.enableR8.fullMode 设置为 true,使用 LazyRow 上的键他们有所帮助,但滚动仍然比带有 recyclerView 的等效 xml 视图应用程序慢。
编辑:添加了 CardComposable …
optimization android lazy-loading android-xml android-jetpack-compose
我正在为我的android应用程序进行国际化.这是我尝试从中获取字符串的方式string.xml
tv.setText(context.getResources().getString(R.string.));
Run Code Online (Sandbox Code Playgroud)
但Eclipse没有提出任何我预先定义的字符串,只是标准Android Strings.我的文件夹结构如下所示:
res/values/strings.xml
Run Code Online (Sandbox Code Playgroud)
和
res/values-NO/strings.xml
Run Code Online (Sandbox Code Playgroud)
我可以看到这些文件中的字符串在文件中有一些内存地址,R.java例如:
public static final int enterPassword=0x7f06003c;
Run Code Online (Sandbox Code Playgroud)
我尝试Clean了Project,但奇怪的是eclipse并没有提出任何建议,字符串存在于R.java
问题出在哪儿 ?
我正在研究一个计算器项目.我实现工作的类无法看到XML布局.当我使用时setContentView(R.layout.),它没有看到任何xml文件.虽然欢迎类工作正常,并将其内容视图设置为欢迎XML.
谁能告诉我为什么这是一个错误?
我正在尝试使用与Card View和Recycler View一起使用的Android教程.我想将OnClickListner附加到每张卡片上.我尝试了stackoverflow上的许多答案,但它们对我不起作用.我的部分代码.
/**
* Adding few albums for testing
*/
private void prepareAlbums() {
int[] covers = new int[]{
R.drawable.album1,
R.drawable.album2};
Album a = new Album("?????", covers[0]);
albumList.add(a);
a = new Album("????", covers[1]);
albumList.add(a);
adapter.notifyDataSetChanged();
}
/**
* RecyclerView item decoration - give equal margin around grid item
*/
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spanCount;
private int spacing;
private boolean includeEdge;
public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
this.spanCount = spanCount;
this.spacing …Run Code Online (Sandbox Code Playgroud)