【问题标题】:I cannot move CircularImageView in toolbar我无法在工具栏中移动 CircularImageView
【发布时间】:2017-10-08 18:23:32
【问题描述】:

几天来,我一直在努力尝试将 CircularImageView 移动到工具栏的右侧,但没有成功。

我想把它放在右边并且更居中(即不接触工具栏边缘),但我做不到。 仅供参考,我尝试同时使用 mikhaellopez 和 hdodenhof 库,但均未成功。

这是我尝试过的(在 CircularImageView 中使用占位符图像):

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:id="@+id/page_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentTop="true"
    android:background="@color/primary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.mikhaellopez.circularimageview.CircularImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profile_pic"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_alignParentEnd="true"
        android:src="@drawable/ic_seed_48dp"
        app:civ_border_color="#FFFFFF"
        app:civ_border_width="3dp" />

    </RelativeLayout>
</android.support.v7.widget.Toolbar>
public class HomepageActivity extends AppCompatActivity {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homepage_activity);
        pageToolbar = (Toolbar) findViewById(R.id.page_toolbar);
        setSupportActionBar(pageToolbar);
        ...
}

另一个问题:是否可以让 CircularImageView 具有纯背景(例如白色)?实际上它不会显示,除非我在其中放了一些东西并且我必须放一个占位符图像。

提前致谢!

【问题讨论】:

    标签: android toolbar circleimage


    【解决方案1】:

    是的,可以只使用纯背景,不要使用您正在使用的库,但使用 hdodenof 可以试试这个:

    app:civ_fill_color="@android:color/white" 
    

    也可以尝试将此添加到您的CircularImageView

    android:layout_alignParentRight="true"
    

    android:layout_alignParentEnd="true" 是 RTL 布局的备份支持,在创建从 RTL 而不是 LTR 呈现布局的应用程序时使用。

    【讨论】:

    • 太棒了,现在可以了,谢谢!只是一个问题:如果我不往里面放点东西,CircularImageView 就会消失。有没有办法让它有一个简单的白色背景?
    • 是的,有:如果你使用 hdodenhof 的库,试试这个:app:civ_fill_color="@android:color/white" 我很高兴它对你有用。请将其标记为答案,以便其他人也能从中受益。
    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2012-11-23
    相关资源
    最近更新 更多