[英]Android Custom Title Bar views not aligning correctly
我有一个自定义标题栏。 这是样式部分。
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:padding">0px</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
<item name="android:windowBackground">@drawable/gradient</item>
</style>
这是XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323331"
android:orientation="horizontal" >
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:src="@drawable/satellite" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/satellite" />
</LinearLayout>
</LinearLayout>
这是该XML的类
public class CustomTitle extends Activity {
protected TextView title;
protected ImageView icon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.customtitle);
title = (TextView) findViewById(R.id.title);
icon = (ImageView) findViewById(R.id.icon);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
}
它的外观如下:
我的问题是,这两个imageviews
(卫星)应该与左侧和右侧对齐。 我似乎无法做到这一点。
有谁知道为什么他们不结盟?
它在Eclipse
的图形布局中正确显示,但是当我在模拟器和物理设备上运行它时,它就像图片一样显示。 我应该提到我的活动扩展了CustomTitle。
从图像视图和linearlayout中删除layout_weight。 也要使用重力,而不要使用layout_gravity。 我认为(我目前没有电脑)可以解决您的问题。 您可以使用的另一种方法是使用相对布局作为根布局,而不是第一个linearlayout,并在图像视图和第二个linearlayout上使用AlignParentLeft和alignParentRight。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.