我遇到一种情况,我需要在垂直排列的单选按钮之间提供间距。
以下是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingRight="20dp"
android:paddingEnd="20dp"
>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My text view"
android:textSize="20dp"
android:textColor="#000000"
android:gravity="center_vertical"
android:background="@drawable/roundedlabel"
/>
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:paddingTop="10dp"
>
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text view1"
android:textSize="20dp"
android:paddingTop="10dp"
/>
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="text view2"
/>
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="text view3"
/>
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="text v4iew"
/>
</RadioGroup>
</LinearLayout>Run Code Online (Sandbox Code Playgroud)
我尝试将android:paddingTop="10dp"每个单选按钮置于文本底部,但是单选按钮保持在同一位置。
谁能帮助我如何在垂直排列的单选按钮之间提供间距?
我正在关注在Android应用程序中使用相机的教程.我在模拟器和物理设备上运行调试时收到错误"权限拒绝:无法使用相机".我在清单文件中尝试了各种权限.似乎大多数有此错误的人都有错误,缺少权限或权限不在其清单中的正确位置.
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.karudo.dbzrealpowerup" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera2" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".DBZHome"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DBZStartPowerUp"
android:label="@string/title_activity_dbzstart_power_up" >
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是我的活动:
package com.example.karudo.dbzrealpowerup;
import android.app.Activity;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.os.Bundle;
import android.util.Size;
import android.view.Menu;
import android.view.MenuItem;
import android.view.TextureView;
import android.widget.Toast; …Run Code Online (Sandbox Code Playgroud) 我非常困惑,因为这看起来应该很简单,但是我无法ListBox使用所选值填充我。我查看了其他几个答案,但无法弄清楚自己在做什么错。
这是我的模型:
public class ItemViewModel
{
public IEnumerable<Item> AllItems { get; set; }
public IEnumerable<Item> SelectedItems { get; set; }
}
public class Item
{
public string Id { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器动作:
public ActionResult ListBoxTest()
{
var viewModel = new ItemViewModel()
{
AllItems = new List<Item>()
{
new Item()
{
Id = "1",
Name = "Name1"
},
new Item()
{
Id = "2",
Name = "Name2"
}
},
SelectedItems …Run Code Online (Sandbox Code Playgroud) 当用户使用默认相机应用程序拍照时,我正在尝试"收听".我使用广播接收器解决方案如下
表现:
<receiver
android:name=".CameraEventReceiver"
android:enabled="true" >
<intent-filter>
<action android:name="com.android.camera.NEW_PICTURE" />
<action android:name="android.hardware.action.NEW_PICTURE" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
收件人:
public class CameraEventReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Cursor cursor = context.getContentResolver().query(intent.getData(), null,null, null, null);
cursor.moveToFirst();
String image_path = cursor.getString(cursor.getColumnIndex("_data"));
Toast.makeText(context, "New Photo is Saved as : -" + image_path, Toast.LENGTH_SHORT).show();
Intent i = new Intent(context, MyAct.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
Run Code Online (Sandbox Code Playgroud)
问题是事件被多次触发(两次).我的断点在哪里context.startActivity(i)被调用两次并且都在行动中android.hardware.action.NEW_PICTURE.
任何原因发生这种情况或如何预防?
谢谢
我用:
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
Run Code Online (Sandbox Code Playgroud)
但它不起作用我想让视频适合屏幕。
请朋友帮助我,我坚持解决这个RecyclerView问题.我是新手,RecyclerView并创建了一个RecyclerView简单的用于管理任务的todo式应用程序.
问题是:
notifyItemRemoved()它有时删除不需要的项目和应用程序崩溃.(可能因为索引网格化了)setAdapter发生意外情况(请参阅#here代码中的标记).颜色在开始时设置为所需的项目,但在向下滚动后,它适用于所有向上滚动的项目.这是我的适配器:
public class RVadapter extends RecyclerView.Adapter<RVadapter.mHolder> {
public List<Task> mTask;
private SQLhelper sql;
private Context mContext;
public RVadapter(Context context)
{
super();
mContext=context;
sql=new SQLhelper(mContext,null);
PlannerAI ai=new PlannerAI();
mTask=ai.generateTaskList(sql.getTasks());
}
public interface listener {
public void refresh();
}
@Override
public void onBindViewHolder(mHolder holder,final int i) {
try {
final Task t = mTask.get(i);
// #here
if(t.getId().equals("Enjoy"))
{
holder.vv.setBackgroundColor(mContext.getResources().getColor(android.R.color.some_color));
}
holder.name.setText(t.getName());
holder.extras.setText(t.getExtras());
holder.id.setText(t.getId());
holder.subject.setText(t.getSubject());
holder.type.setText(t.getType());
holder.noq.setText(t.getNo()+" …Run Code Online (Sandbox Code Playgroud) 在我的自定义视图中,我有一个运行简单游戏的Java类.当游戏结束时,我想显示我的DialogFragment,但getFragmentManager()方法似乎未定义.
FragmentManager manager = getFragmentManager();
Finish finish = new Finish();
finish.show(manager, "done");
Run Code Online (Sandbox Code Playgroud)
我试过让经理通过一个Fragmentobj:
Fragment fragment = new Fragment();
FragmentManager manager = fragment.getFragmentManager();
Run Code Online (Sandbox Code Playgroud)
但是返回为null.我知道这是一个新Fragment实例,但我不确定给它带来什么价值.任何帮助将非常感激.
我试图让mcc和mnc一个后SIM LOADED状态,以检查SIM卡的确发生了变化没有READ PHONE STATE权限,以禁用某些网络应用程序的请求,并在一些国家,用户不想要的.
由于getSimOperator()可能会根据当前的运营商进行更改(例如,当用户正在漫游时),我决定使用getNetworkOperator().
虽然这种方法可以返回null即使SIMIS LOADED,可能会返回不同的结果,如莱卡移动通讯卡仅限GSM连接是给我mnc = 01,当我把SIM卡取出并再次把它放在它给了我mnc = 04.
有人知道为什么mnc会给出不同的结果getNetworkOperator()吗?哪种方法更好,getNetworkOperator()或者getSimOperator()对于这种情况?
此外,我不能使用,getResources().getConfiguration().mcc因为它给出一个int数字可能会删除0之前,例如给出4而不是04.
这是我检查SIM状态更改的代码:
@Override
public void onReceive(final Context context, Intent intent) {
if (intent != null) {
Bundle extras = intent.getExtras();
if (extras != null) {
String ss = extras.getString(EXTRAS_SIM_STATUS);
if (ss != null …Run Code Online (Sandbox Code Playgroud) 创建一个MediaPlayer.特定类具有播放,暂停和恢复的功能.我正在尝试制作一个SeekBar能显示进度的东西.
SeekBar要求作为maxlength从getDuration()调用mediaplayer.getDuration()函数的函数获得的值并返回该值.
SeekBar还需要从getCurrentPostion()函数中获得的当前位置的值.他们俩都回来了NullPointerException.
public class PlayMedia extends AsyncTask<Void, Void, Void>
implements MediaPlayer.OnPreparedListener {
private MediaPlayer mediaPlayer;
int length;
int duration =0;
int currentPosition=0;
@Override
protected Void doInBackground(Void... params) {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/Notate/"+MainActivity.filepath+".wav");
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
}
return null;
}
@Override
protected void onPostExecute(Void …Run Code Online (Sandbox Code Playgroud) 我正在尝试RecyclerView和GridLayoutManager。
我最终希望显示与此相同大小的图像,或者如果可能的话甚至是方形的:
GridLayoutManager使这成为可能的要素是什么?我是否修改用于填充的单个项目 XML RecyclerView?
我希望我的应用程序在用户更改语言环境时随时都能识别.所以在我的Application班上,我创建了一个receiver听取系统意图ACTION_LOCALE_CHANGED:
public final class MyApp extends Application {
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
String locale = Locale.getDefault().getCountry();
Toast.makeText(context, "LOCALE CHANGED to " + locale, Toast.LENGTH_LONG).show();
}
};
@Override public void onCreate() {
IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(myReceiver, filter);
}
}
Run Code Online (Sandbox Code Playgroud)
当我按下主页并转到设置应用程序以更改我的区域设置时,不会显示Toast.在里面设置断点onReceive表明它永远不会被击中.
我有一个BottomSheetDialogFragment从另一个片段打开.
bottom_sheet_fragment.xml:
<LinearLayout>
<TabLayout/>
<ViewPager>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有两个视图寻呼机片段,每个片段包含一个EditText和一个RecyclerView垂直方式.
view_pager_fragment1.xml:
<LinearLayout>
<EditText/>
<RecyclerView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在,当我点击编辑文本时,回收站视图的一部分隐藏在键盘后面.
预期: 当键盘出现时,底部表格应向上滚动,以便回收者视图内容保持可见.
android-layout android-softkeyboard android-fragments bottom-sheet
tname如下表:
id name status
1 name1 0
2 name2 0
3 name3 0
4 name4 0
我为上面名为 的表创建了一个模型Tname,然后我想对该表进行分块并更改表中的“状态”:
$midModel = Tname::where('status', 0);
$midModel->chunk(1, function ($rows) {
foreach ($rows as $row) {
Tname::where('id', $row->id)
->update([
'status' => 1,
]);
}
});
Run Code Online (Sandbox Code Playgroud)
第一行状态改变后,'chunk' 会漏掉第二行,我的问题是如何分块where('status', 0)并且不会漏掉行?我尝试放入where('status', 0)then 块,但它每次都会将表中的所有行分块。