gpt4 book ai didi

java - 我可以锁定 ImageView 的位置吗?

转载 作者:行者123 更新时间:2023-12-01 09:43:27 25 4
gpt4 key购买 nike

编辑:对于像我这样只想将图像锁定在屏幕左上角的人,您可以设置一个 Logo 来替换角落中的应用程序启动器图标,这样就完成了这很容易。

我希望 ActionBar 中屏幕的左上角有一个图像,而不是应用程序的图标和名称。到目前为止,我已经到达那里,但它的移动和大小取决于操作栏中的其他图标(我有图标出现和消失)。它还以剩余空间为中心,而不仅仅是在中心。

有没有办法可以将此图像锁定到左角?这就是将其放入下面的 ActionBar 中的方法。

public void ActionBarCreation(){
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
ImageView img = new ImageView(getApplicationContext());
img.setImageResource(R.drawable.my_image);
// 7 padded on the bottoms so it does not cover the dividing line.
img.setPadding(0, 0, 0, 7);
getActionBar().setCustomView(img);
getActionBar().setDisplayShowCustomEnabled(true);
}

最佳答案

将您的应用程序主题设置为

<android:theme="@android:style/Theme.NoTitleBar">

-> 这将删除带有应用程序名称的默认工具栏。

接下来在 Activity 布局中添加您自己的工具栏布局

<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="256dp"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"

>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_horizontal"
android:id="@+id/image"

//your drawable and customizations here
android:background="@android/color/transparent"
/>

</android.support.v7.widget.Toolbar>

现在将此工具栏设置为您的 Activity 的工具栏:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowHomeEnabled(false);
}}

关于java - 我可以锁定 ImageView 的位置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38267178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com