小编Nic*_*lli的帖子

如何将TextView中的文本与Compound Drawable垂直对齐

这个问题在某种程度上延续了我的上一个问题.

我现在的问题几乎是一样的,除了不是在不同视图中分离图像和文本(即ImageView和TextView),我学会了我可以使用该属性android:drawableLeft为我的文本设置一个图像(建议指向我由Eclipse在LinearLayout行上带有警告图标).

我认为唯一的区别是,而不是与设置ImageView的setImageResource()方法,我想简单地设置的TextView的drawableLeft与归因setCompoundDrawablesWithIntrinsicBounds()方法.相反,当我做出改变时,我回到了原来的问题:文本与视图的上边缘而不是中心对齐.

这就是我的TextView的样子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >       
    <TextView 
        android:id="@+id/account_login"
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/pm_gmail"
        android:drawablePadding="8dp"
        android:text="example@gmail.com"
        android:paddingLeft="16dp"
        android:layout_gravity="left|center_vertical" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_centerVertical="true"
        android:layout_below="@id/account_login"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="5dp"
        android:background="#DDDDDD" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

第二个View只是一个分隔符.

...这就是设置上述属性后布局的样子:(我没有足够的声誉来发布图片,所以这里是它的链接)

(为了清楚起见,这只是一个静态示例.我的文本和图像都是在运行时在代码中动态设置的).

任何帮助是极大的赞赏.

layout android textview android-layout compound-drawables

11
推荐指数
1
解决办法
5812
查看次数

背景SwingWorker线程不执行特定的代码段

我找不到更好的方式在问题的标题中表达问题,但希望你能理解......

我有以下代码......

[...]
final JDialog waitingDialog = optionPane.createDialog(optionPane, "Processing in backgroung");

waitingDialog.setLocationRelativeTo(homeFrame);
waitingDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);


SwingWorker<Void, Void> backgroundThread = new SwingWorker<Void, Void>() {

    @Override
    protected Void doInBackground() throws Exception {
        // Background processing is done here
        System.out.println("[DEBUG] -- Background processing has started");
        MyCustomClass.initParameters();
        System.out.println("DEBUG] -- initParameters() has finished. Starting main processing now...");
        waitingDialog.setVisible(true);
        MyCustomClass.run();
        return null;
    }

    // This is called when background thread above has completed
    @Override
    protected void done() {
        waitingDialog.dispose();
    };
};
backgroundThread.execute();

[and does other things after this...] …
Run Code Online (Sandbox Code Playgroud)

java debugging swing multithreading swingworker

1
推荐指数
1
解决办法
1552
查看次数