Jump to content

custom View actionbar(appcompat)


emanuelx
 Share

Recommended Posts

boas, estou a tentar fazer uma actionbar modificada, mas estou a ter um problema com a interface,

u5t27OFl.png

Supostamente não devia ter esses espaços entre as imagens(ImageView).

Alguem sabe como é que eu posso meter o customView a ocupar a area toda, e sem espaços entre as imagens?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f2f2f2"
android:orientation="horizontal" >
<ImageView
	android:id="@+id/imageView1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_alignParentLeft="true"
	android:layout_alignParentTop="true"
	android:src="@drawable/search" />
<ImageView
	android:id="@+id/imageView2"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_alignParentRight="true"
	android:layout_alignParentTop="true"
	android:src="@drawable/navegacao" />
<ImageView
	android:id="@+id/imageView3"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_alignParentTop="true"
	android:layout_toLeftOf="@+id/imageView2"
	android:src="@drawable/bolas" />
</RelativeLayout>
 
ActionBar actionBar = getSupportActionBar();
 LayoutInflater li = LayoutInflater.from(this);
 View customView = li.inflate(R.layout.actionbar_styled, null);
 actionBar.setCustomView(customView);

com calma e sem stresses

Link to comment
Share on other sites

Boas,

nao sei se ja conseguiste resolver ou nao, mas estive a testar o teu codigo, e pareceu-me tudo ok.

Confirma que as tuas imagens nao teem elas proprias esse espacamento (ou margens).

Outra alternativa poderia ser usares antes um FrameLayout em vez de RelativeLayout, algo tipo:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f2f2f2" >

<ImageView
	android:id="@+id/imageView1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_gravity="left"
	android:src="@drawable/image1" />

<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:layout_gravity="right"
	android:orientation="horizontal" >

	<ImageView
		android:id="@+id/imageView2"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:src="@drawable/image2" />

	<ImageView
		android:id="@+id/imageView3"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:src="@drawable/image3" />
</LinearLayout>
</FrameLayout>

O uso de RelativeLayouts apesar de ser bastante poderoso, é tambem bastante pesado. O resultado que pretendes pode ser igualmente alcancado usando apenas um FrameLayout com um LinearLayout (que sao os layouts mais leves em Android), e as respetivas imagens.

Espero que ajude,

cc

Edited by coxosclassic

Cumps,

cc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.