在这个,这个和这个线程我试图找到如何在单个视图上设置边距的答案.但是,我想知道是否有更简单的方法.我会解释为什么我宁愿不想使用这种方法:
我有一个自定义Button,扩展了Button.如果背景设置为默认背景以外的其他内容(通过调用setBackgroundResource(int id)或setBackgroundDrawable(Drawable d)),我希望边距为0.如果我这样称呼:
public void setBackgroundToDefault() {
backgroundIsDefault = true;
super.setBackgroundResource(android.R.drawable.btn_default);
// Set margins somehow
}
Run Code Online (Sandbox Code Playgroud)
我希望边距重置为-3dp(我已经在这里阅读如何从像素转换为dp,所以一旦我知道如何在px中设置边距,我就可以自己管理转换).但是因为这是在CustomButton类中调用的,所以父级可以从LinearLayout变为TableLayout,而我宁愿不让他得到他的父级并检查该父级的实例.我想,这也将是非常无形的.
另外,在调用时(使用LayoutParams)parentLayout.addView(myCustomButton, newParams),我不知道这是否将它添加到正确的位置(但是没有尝试过),比如一行五的中间按钮.
问题:除了使用LayoutParams之外,还有更简单的方法以编程方式设置单个按钮的边距吗?
编辑:我知道LayoutParams方式,但我想要一个避免处理每个不同容器类型的解决方案:
ViewGroup.LayoutParams p = this.getLayoutParams();
if (p instanceof LinearLayout.LayoutParams) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)p;
if (_default) lp.setMargins(mc.oml, mc.omt, mc.omr, mc.omb);
else lp.setMargins(mc.ml, mc.mt, mc.mr, mc.mb);
this.setLayoutParams(lp);
}
else if (p instanceof RelativeLayout.LayoutParams) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)p;
if (_default) lp.setMargins(mc.oml, …Run Code Online (Sandbox Code Playgroud) 我正在遵循如何添加a的标准示例RatingBar.控制我试图使用的星星数量android:numStars="5".问题是星星的数量似乎根本不起作用.在纵向布局中,我获得了6颗星,当我翻动手机时,我得到了大约10颗星.我试图在我的Activity(myBar.setNumStars(5))中设置加载xml 的星数,但是该选项也没有成功.
所以我的问题是如何定义我的布局,以便它只显示五颗星?设置numStars似乎不起作用.
罗兰,提前谢谢
我有一个PreferenceCategoryxml文件,我已经在其中定义了所有首选项,我从扩展的类中调用它PreferenceActivity.我无法设置我的设置屏幕的背景,此屏幕显示在下面显示的xml文件的帮助下.请看我已经定义了android:background="#041A37",仍然屏幕仍然是默认颜色:黑色.
public class MyPreferenceActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
Context mContext=super.getBaseContext();
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.preference);
//v.setBackgroundColor(Color.rgb(4, 26, 55));
}
}
Run Code Online (Sandbox Code Playgroud)
preference.xml是
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#041A37" >
<PreferenceCategory>
<com.dropcall.SeekBarPreference
android:background="#041A37"
android:defaultValue="5"
android:key="@string/Interference_Delay"
android:progressDrawable="@drawable/seekbardrawable"
android:title="Seconds Delay until intereference" />
<com.dropcall.SeekBarPreference2
android:defaultValue="30"
android:key="@string/Drop_Delay"
android:progressDrawable="@drawable/seekbardrawable"
android:title="Seconds delay until drop" />
<CheckBoxPreference
android:background="@drawable/state_normal"
android:defaultValue="true"
android:key="@string/Drop_Option"
android:title="Close after call drop" />
<CheckBoxPreference
android:background="@drawable/state_normal"
android:defaultValue="true"
android:key="@string/Timer_Option"
android:title="Start timers on launch" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
虽然我已经设置android:background="#041A37"了每个文件,但背景并没有变成深蓝色或任何其他颜色.它仍然是默认颜色,黑色.如何更改背景颜色.请告诉我任何指示/提示,如果您遇到同样的问题,请告诉我您为设置背景颜色所做的更改.
我创建了一个Windows窗体解决方案,并在我调用的类的构造函数中
Console.WriteLine("constructer called")
但我只得到表单而不是控制台..所以输出在哪里?
在Eclipse中我曾经使用过一个组合(首先按Shift+ Alt+ A,然后按下S)来提取字符串strings.xml但我在Intellij上找不到它.在Intellij上怎么做?
我尝试按下一个打开相机并拍照的按钮.我的代码在这里
//for imports check on bottom of this code block
public class HomeProfileActivity extends AppCompatActivity {
//Button camera
public static final String TAG = HomeProfileActivity.class.getSimpleName();
public static final int REQUEST_TAKE_PHOTO = 0;
public static final int REQUEST_TAKE_VIDEO = 1;
public static final int REQUEST_PICK_PHOTO = 2;
public static final int REQUEST_PICK_VIDEO = 3;
public static final int MEDIA_TYPE_IMAGE = 4;
public static final int MEDIA_TYPE_VIDEO = 5;
private Uri mMediaUri;
private ImageView photobutton;
private Button buttonUploadImage, buttonTakeImage;
protected void onCreate(Bundle …Run Code Online (Sandbox Code Playgroud) 此代码创建通知.如果单击它,则运行当前应用程序(意图创建于Entry,这是我唯一的Activity),是Android开发人员博客的略微修改版本:
private void makeIntent() {
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.prev, "Status message!", System.currentTimeMillis());
Intent intent = new Intent(this, Entry.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
note.setLatestEventInfo(this, "New Email", "Unread Conversation", pi);
note.flags |= Notification.FLAG_AUTO_CANCEL;
mgr.notify(NOTIFY_ME_ID, note);
}
Run Code Online (Sandbox Code Playgroud)
但我不想开始任何活动,而只是在当前活动中运行一个方法.从我到目前为止所读到的内容来看,我想我必须使用像startActivityForResult()使用intent-filters和实现这样的方法onActivityResult(),但是在弄乱了所有这些东西之后,改变了Intent和中的东西PendingIntent,我仍然没有可用的结果.是否有可能以某种方式调用一个方法Entry(我的主要Activity,在其中Intent创建),或者Intents当我点击我的新制作时捕获任何传出或传入Notification?
PS.我很抱歉,如果这是一个重复的线程,那么现在很慢,我无法正常搜索.
android android-intent android-notifications android-activity
我只是想找出如何制作深层副本的最佳解决方案HashMap.此映射中没有实现的对象Cloneable.我想找到比序列化和反序列化更好的解决方案.
我正在尝试为Selenium编写自己的ExpectedConditions,但我不知道如何添加新的.有人有例子吗?我在网上找不到任何教程.
在我目前的情况下,我想等到元素存在,可见,启用并且没有attr"aria-disabled".我知道这段代码不起作用:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
return wait.Until<IWebElement>((d) =>
{
return ExpectedConditions.ElementExists(locator)
&& ExpectedConditions.ElementIsVisible
&& d.FindElement(locator).Enabled
&& !d.FindElement(locator).GetAttribute("aria-disabled")
}
Run Code Online (Sandbox Code Playgroud)
编辑:一些额外的信息:我遇到的问题是使用jQuery选项卡.我在禁用的选项卡上有一个表单,它将在选项卡变为活动状态之前开始填写该选项卡上的字段.
我试图插入整数PriorityQueue,我知道:
如果在PriorityQueue构造a时未指定比较器,则使用存储在队列中的数据类型的默认比较器.默认比较器将按升序对队列进行排序
但是,我得到的输出不是按排序顺序.运行以下代码后的输出是:[2, 4, 8, 6]
public static void main(String args[]) {
PriorityQueue<Integer> q = new PriorityQueue<Integer>(10);
q.offer(4);
q.offer(2);
q.offer(8);
q.offer(6);
System.out.print(q);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下原因吗?