我试图在我现有的画布中添加一些红色矩形,与特定的盒子一样,与预期的结果图像完全一样,但它们根本不显示,因为我的代码显示了当我部署应用程序时当前不希望的结果.我的代码是在顶行创建4个矩形,在底行创建4个矩形,但我只想在盒子2-6的顶部添加它,但我知道需要为盒子顶部的红色矩形添加额外的代码1和7.有谁知道我做错了什么以及如何解决这个问题?所有帮助将不胜感激.
public class RectangleTextView extends View {
private final Paint mBlackPaint = new Paint();
private final Paint mRedPaint = new Paint();
private final TextPaint mTextPaint;
public RectangleTextView(Context context, AttributeSet attrs) {
super(context, attrs);
int valueInDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
int valueInSp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics());
mRedPaint.setColor(Color.parseColor("#CC3333"));
mBlackPaint.setAntiAlias(false);
mBlackPaint.setColor(Color.BLACK);
mBlackPaint.setStrokeWidth(valueInDp);
mBlackPaint.setStyle(Paint.Style.STROKE);
mTextPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(Color.BLACK);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mTextPaint.setTextSize(valueInSp);
mWindowPaint = new Paint();
mWindowPaint.setColor(Color.parseColor("#CC3333"));
mWindowPaint.setStrokeWidth(valueInDp);
}
private Paint mWindowPaint;
@Override protected void onDraw(Canvas canvas) {
super.onDraw(canvas); …
Run Code Online (Sandbox Code Playgroud) 出于某种原因,在重建我的项目后,我得到了一个非法的字符错误,但我的代码中的任何内容都没有用红色加下划线.有人可以告诉我有什么问题以及如何解决?
错误
illegal character: \8204
Run Code Online (Sandbox Code Playgroud)
WCBankActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
public class WCBankActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "Station_key";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_wc_bank);
if (savedInstanceState == null) {
Intent intent = getIntent();
String station = intent.getStringExtra(WCBankActivity.EXTRA_MESSAGE);
FragmentWCBank newFragment = new FragmentWCBank();
FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();?
transaction.replace(R.id.detail_container, newFragment);
transaction.commit();
}
}
}
Run Code Online (Sandbox Code Playgroud)
java android android-intent android-fragments android-studio
我刚刚制作了2张图纸,试图让其中一张看起来与另一张相同,但我没有运气.关于屏幕截图,顶部的绘图是使用画布创建的,底部的绘图是使用XML创建的.XML绘图对我来说是完美的,但不幸的是根据Android,我不应该使用它,因为它返回"太多视图"警告.我已经尝试了以下方法用于画布绘制,但我仍然没有得到所需的结果.
我已经在十几个仿真器上测试了这个项目,尽管XML绘图有很多视图,但它们都只需要一秒钟就能显示出来.
有没有人知道有什么其他选项可以解决这个恼人的画布问题,并确保画布绘图看起来与XML绘图完全相同,无论屏幕大小和方向如何?此情景中是否应忽略"太多视图"警告和/或我将查看次数限制增加到80以上?所有相关的帮助将受到高度赞赏.
Java代码
XML代码
我注意到有几个来源鼓励开发人员在他们的项目中只使用单个活动。什么时候在一个项目中进行超过 1 项活动比较合适?活动可以拥有的可组合项数量是否有限制?我担心的一个问题是,对于需要多个屏幕的大型项目,这可能会导致大量代码,最终将变得耗时且难以滚动和查找。
使用 Plotly.js 创建堆栈条形图后,我注意到它不响应不同的屏幕宽度。如何使图形响应自动适应屏幕宽度的调整大小?
我尝试使用以下方法,但没有用:
window.onresize = function() {
Plotly.Plots.resize('myDiv');
};
Run Code Online (Sandbox Code Playgroud)
window.onresize = function() {
Plotly.Plots.resize('myDiv');
};
Run Code Online (Sandbox Code Playgroud)
var trace1 = {
x: ['Category A', 'Category B', 'Category C', 'Category D ', 'Category E', 'Category F', 'Category G', 'Category H'],
y: [20, 14, 23, 20, 14, 23, 34, 26],
marker: {
color: ['rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)', 'rgba(0,152,212,0.5)']
},
name: 'Item 1',
type: 'bar'
};
var trace2 = {
x: ['Category A', 'Category B', 'Category C', 'Category D ', 'Category …
Run Code Online (Sandbox Code Playgroud)在按照本教程创建首选项屏幕之后,膨胀类“ androidx.preference.PreferenceScreen”似乎存在问题。为什么在res/xml
文件夹中声明了我的首选项并且已将必需的依赖项添加到此项目后,为什么找不到它?
我的应用程序的minSdkVersion是24。
错误膨胀类(未找到)androidx.preference.PreferenceScreen
依存关系
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)
res / xml / preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="preference_a"
android:defaultValue="false"
android:title="Preference A" />
</androidx.preference.PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
活动布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/settings_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MySettingsActivity" />
Run Code Online (Sandbox Code Playgroud)
活动课
class MySettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager …
Run Code Online (Sandbox Code Playgroud)
Boolean literal argument without parameter name
当参数名称显示在值的左侧时,为什么会出现此警告Boolean
?我知道如何解决这个问题,但是警告是否必须修复,或者我可以保持原样吗?该Boolean
值将来会定期更改,因此我更喜欢易于调整的代码。
项目的数据类
data class Food (val foodName: String,
val hasDairy: Boolean,
val hasGluten: Boolean,
val hasSoya: Boolean,
val hasWheat: Boolean)
Run Code Online (Sandbox Code Playgroud)
片段类
...
myList.add(Food(getString(R.string.name_of_food),
true,
false,
true,
false))
...
Run Code Online (Sandbox Code Playgroud) 如何使用颜色资源更改 Jetpack Compose 中 MD3 顶部应用栏的背景颜色?
可以理解的是,有一个colors
属性可用,但尚不清楚用于上述用途的用途。
颜色.kt
val MyColor = Color(0,5,5,255)
Run Code Online (Sandbox Code Playgroud)
MainActivity.kt
MediumTopAppBar(title = {Text(text = "")})
Run Code Online (Sandbox Code Playgroud) android kotlin material-design android-jetpack-compose android-jetpack-compose-material3
如何将切换案例方案与字符串资源而不是硬编码名称一起使用?我的字符串与它们的拼写完全相同。
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MainListAdapter adapter = (MainListAdapter) parent.getAdapter();
Main continent = adapter.getItem(position);
if (mTwoPane) {
View rowView = view;
setItemSelected(continent, rowView);
Fragment newFragment;
switch (stringRes) {
case R.id.africa:
newFragment = new FragmentAfrica();
break;
case R.id.asia:
newFragment = new FragmentAsia();
break;
case R.id.europe:
newFragment = new FragmentEurope();
break;
default:
newFragment = new FragmentAfrica();
}
MainActivity activity = (MainActivity) view.getContext();
FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.detail_container, newFragment);
transaction.commit();
} else {
}
Run Code Online (Sandbox Code Playgroud) Android Studio 有没有办法显示 XML 布局中存在的视图数量?众所周知,布局应该包含 <=80 个视图,因此超过这个数量就会出现此警告,因此告知数量将非常有帮助。
LayoutName.xml 有 80 多个视图,对性能不利
public class FragmentApple extends android.support.v4.app.Fragment {
public FragmentApple () {
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_apple,container,false);
int num = FragmentApple.getChildCount(); Log.d("Number of views in layout: ", "" + num);
return v;
}
}
Run Code Online (Sandbox Code Playgroud) android ×9
java ×4
kotlin ×4
xml ×3
android-view ×2
android-jetpack-compose-material3 ×1
data-class ×1
html ×1
javascript ×1
plotly ×1