我正在尝试创建一个半透明的帮助叠加层,以便在用户首次打开应用程序时显示在我的活动的主屏幕上。我想通过“剪切”与按钮位置相对应的覆盖层部分来突出显示主布局中包含的按钮(并使用 setContentView 进行膨胀),并使剪切部分透明。
覆盖层是一个以编程方式创建的视图(扩展了RelativeLayout),它被添加到我的活动的主FrameLayout中,如下所示:
private void addHelpOverlay(){
HelpOverlay help = new HelpOverlay(this);
help.setBackgroundColor(Color.parseColor("#BB222222"));
mainLayer.addView(help);
}
public class HelpOverlay extends RelativeLayout{
public HelpOverlay(Context context){
super(context);
}
@Override
public void dispatchDraw(Canvas canvas){
canvas.drawColor(Color.parseColor("#BB222222"));
Paint mPaint = new Paint();
mPaint.setColor(0xFFFFFF);
mPaint.setAlpha(0);
mPaint.setAntiAlias(true);
canvas.drawCircle(buttonX, buttonY, 100, mPaint);
super.dispatchDraw(canvas);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码实际上没有显示任何内容,只是没有圆形切口的半透明布局。我认为这是因为它只是在半透明布局的顶部绘制了一个透明的圆圈。我真的很努力实现这一目标,任何建议将不胜感激!
图像你有一个ImageView,它在一个不移动的层上占据整个屏幕,这个层是恒定的,为什么上层在转换到新片段时会移动,然后你在其顶部的可移动层上有另一个ImageView 。我的问题是是否有办法混合两层?
有没有更好的方法来完成我上面描述的事情?
我想创建ViewPager一个围绕它的getWidth()和getHeight()轴旋转的滑动。我尝试过,但所有这些转换只能通过具有各种效果的垂直和水平来实现。
有什么方法或提示可以开发这种类型ViewPager吗?
编辑 - 解释它会是什么样的旋转
Axis - getWidth,getHeight应该是枢轴点,一旦我滑动它就应该旋转,对于下一页,它应该从 (0, getHeight) 轴旋转。为了简化,考虑这个简单的场景——
ViewPager应该从第 1 页旋转到第 2 页。ViewPager应该从第 1 页旋转到第 4 页。getWidth,getHeight第1页。因此,对于下一页,它将始终为0,getHeight作为轴,而对于上一页,将始终为getWidth,0作为轴。如果一个高程=5dp的按钮附加到一个高程=5dp的LinearLayout上,
我们是否仍然看到按钮与 LinearLayout 处于同一级别或高于它的 5dp?
因为RecyclerView如果它没有任何项目,则单击RecyclerView有效,但如果它有项目,则单击RecyclerView不起作用。小心我的意思是点击 just RecyclerViewnotRecyclerView的项目
recyclerView.setOnClickListener(view -> {Timber.d("recyclerView clicked");});
Run Code Online (Sandbox Code Playgroud)
RecyclerView即使上面有项目,我如何设置可点击。
android view android-layout android-view android-recyclerview
我有一个seekbar和 一个ImageView。在搜索栏移动时,我相应地缩放图像视图。下面是我的完整代码
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context="com.app.pdf.pdfmetadata.Main2Activity">
<FrameLayout
android:background="#20000000"
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@android:drawable/ic_dialog_info"/>
</FrameLayout>
<SeekBar
android:id="@+id/seekbar"
android:min="1"
android:max="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
Java代码
public class MainActivity extends AppCompatActivity {
private static final String TAG = "Main2Activity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View imageView = findViewById(R.id.imageView);
SeekBar seekBar = findViewById(R.id.seekbar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { …Run Code Online (Sandbox Code Playgroud) 慢慢学习 Kotlin。只是从一卷中生成一个随机数。如果 roll = 9 我想让按钮和搜索栏不可见。
我正在使用 toggleVisibility 函数来完成此操作,但 Kotlin 编译器将 isVisible 视为未解析的引用
package com.example.randomizer
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.SeekBar
import android.widget.TextView
import android.widget.VideoView
import java.util.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rollButton = findViewById<Button>(R.id.rollButton)
val resultsTextView = findViewById<TextView>(R.id.resultsTextView)
val seekBar = findViewById<SeekBar>(R.id.seekBar)
val winText = "9 You Win !"
rollButton.setOnClickListener {
val rand = Random().nextInt(seekBar.progress)
resultsTextView.text = rand.toString()
if (rand == 9) {
resultsTextView.text = winText
seekBar.toggleVisibility() …Run Code Online (Sandbox Code Playgroud) 我的主要活动中有此功能,但不显示徽章:
private fun setFindShiftBadge(state: HomeState) {
val findShiftsBadge = BadgeDrawable.create(this)
home_framelayout.foreground = findShiftsBadge
findShiftsBadge.badgeGravity = BadgeDrawable.TOP_END
findShiftsBadge.backgroundColor = resources.getColor(R.color.colorWhite)
findShiftsBadge.badgeTextColor = resources.getColor(R.color.colorPrimary)
findShiftsBadge.number = state.availableShifts.size
}
Run Code Online (Sandbox Code Playgroud)
在同一个活动中,我有这个显示徽章的功能:
private fun setMyPostedShiftBadge(state: HomeState) {
val userShiftsBadge: BadgeDrawable =
bottom_navigation_view.getOrCreateBadge(R.id.bottom_navigation_my_posted_shifts_text)
userShiftsBadge.number = state.userShifts.size
userShiftsBadge.backgroundColor = resources.getColor(R.color.colorPrimary)
}
Run Code Online (Sandbox Code Playgroud)
现在我明白第二个函数可以工作,因为徽章设置在BottomNavigationView. 具有讽刺意味的是,BottomNavigationView扩展FrameLayout。在 Android 文档中:
使用 attachBadgeDrawable(BadgeDrawable, View, FrameLayout) 将 BadgeDrawable 作为 ViewOverlay 添加到所需的锚视图。使用 updateBadgeCoordinates(View, ViewGroup) 根据锚视图更新 BadgeDrawable BadgeDrawable 的坐标(中心和边界)。
他们说要使用这段代码,For API 18+ (APIs supported by ViewOverlay)我在第一个不起作用的函数中使用了它:
BadgeDrawable badgeDrawable …Run Code Online (Sandbox Code Playgroud) android badge android-view android-drawable android-framelayout
我正在尝试实现夜间模式,但我遇到了问题:CardView不会将颜色更改为night值,但活动正确地将其背景更改为夜间颜色值。

请帮助理解这个问题。
MainActivity
public class NewFinishActivity extends AppCompatActivity {
@BindView(R.id.finishRecycler)
RecyclerView finishRecycler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
setContentView(R.layout.activity_new_finish);
ButterKnife.bind(this);
LevelRecyclerAdapter mAdapter = new LevelRecyclerAdapter(getApplicationContext(), new ArrayList<>());
finishRecycler.setAdapter(mAdapter);
}
}
Run Code Online (Sandbox Code Playgroud)
MainActivity 布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
android:background="@color/background_color"
tools:context=".activities.NewFinishActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/finishRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
适配器
public class LevelRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<UserLevel> mItems;
private Context mContext;
public LevelRecyclerAdapter(Context context, List<UserLevel> items) {
mContext = context; …Run Code Online (Sandbox Code Playgroud) android android-layout android-view android-recyclerview android-darkmode
我试图LinearLayout在 Android 的 XML 布局中设置 a 的填充。但它给了我 2 个选择 -paddingLeft和paddingStart.
有什么区别,使用更正确/更好的属性之一是什么?
我想要最好的答案,因为这需要最优质的代码。
android android-layout right-to-left android-xml android-view
android ×10
android-view ×10
android-xml ×1
badge ×1
blending ×1
java ×1
kotlin ×1
layer ×1
view ×1