【问题标题】:how to centering the image and text inside layout android如何在布局android中居中图像和文本
【发布时间】:2018-04-04 15:52:13
【问题描述】:
 <TextView
    android:id="@+id/tv_connStatus"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_gravity="center"
    android:background="#C5CAE9"
    android:drawableLeft="@drawable/circle_gr"
    android:gravity="center|left"
    android:padding="5dp"
    android:text="TextView"
    android:textStyle="bold" />

我尝试了两个中心,但图像留给了我。我希望图像和文本位于文本视图的中心

【问题讨论】:

  • 我试过了,但是使用自定义进度对话框我们可以做到这一点。我尝试进行中的对话框功能
  • 请提供您的部分代码......
  • @jesu,把代码写在你的帖子里。
  • 我通过在高度和宽度的线性布局中使用换行内容得到它

标签: android


【解决方案1】:
private class UpdateFeedTask extends AsyncTask<MyActivity, Void, Void> {

private ProgressDialog mDialog;

protected void onPreExecute() {
    Log.d(TAG, " pre execute async");
    mDialog = ProgressDialog.show(MyActivity.this,"Please wait...", "Retrieving data ...", true);

}

protected void onProgressUpdate(Void... progress) {
    Log.d(TAG, " progress async");     
}

@Override
protected Void doInBackground(MyActivity... params) {
    // TODO Auto-generated method stub
    return null;
}

protected void onPostExecute(Void result) {
    Log.d(TAG, " post execute async");
    mDialog.dismiss();
} }

参考 - Click Here

【讨论】:

    【解决方案2】:

    我通过重心使图像和文本居中,并在文本视图中包裹高度和宽度

    <LinearLayout
            android:id="@+id/ll_chatconnectionStatus"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:gravity="center"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/tv_chatconnectionStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@color/sandal_color"
                android:drawablePadding="5dp"
                android:drawableStart="@drawable/circle_bl"
                android:hint="@string/connection_status"
                android:padding="5dp"
                android:textColor="@color/blacktext"
                android:textStyle="bold" />
        </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 1970-01-01
      • 2017-07-06
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多