0

I want to restrict the title in my app in landscape to e.g. 50% of the area on the left side. Is it possible to have something like:

Title only on the right (resp. left) side

For the portrait modus the current situation is fine.

Currently the title is already a custom title, but would be great to give the user more space :)

LeO
  • 4,238
  • 4
  • 48
  • 88
  • create dimen.xml and set values for that http://stackoverflow.com/a/11686495/1012284 – Padma Kumar Sep 05 '12 at 15:25
  • Thx for the hint, but I still don't know how to restrict the title width to the right/left side. I don't get a real clue how this might help to restrict the width, cause it's only about the height... – LeO Sep 05 '12 at 20:08
  • do u know aboutEMS? try giving android:maxEms="10". you can give any integer values. – Padma Kumar Sep 06 '12 at 06:09
  • No, I didn't know about the ems, but didn't change anything. I put them into the Style, but not recognized there. In the title.xml there was also no change for the components. But I guess its due to the fill of the title which covers the whole area... – LeO Sep 06 '12 at 09:32
  • Without showing your code I cant do any thing @LeO. – Padma Kumar Sep 06 '12 at 09:43
  • True ;) How to post the code properly? [main-landscape](https://code.google.com/p/cuckoochess/source/browse/trunk/DroidFish/res/layout-land/main.xml) with the corresponding title.xml [title-land and portrait](https://code.google.com/p/cuckoochess/source/browse/trunk/DroidFish/res/layout/title.xml) I tried some changes, but I didn't succeed... – LeO Sep 06 '12 at 10:09

3 Answers3

1

That title is part of the View (or Fragment?) on the right side of the screen. To do the same, simply put your title in a View that resides on the left half of the screen. You can use your already-existing layout for portrait orientation.

EDIT: Based on the image provided, I think that the layout of that application looks something like this:

_______________________________
|              |--------------|
|              ||   Title    ||
|              |--------------|
|    View A    |    View B    |
|              |              |
|              |              |
|              |              |
-------------------------------

and in terms of hierarchical layout, something like this:

Layout
  View A
    Stuff
  View B
    Title
    More Stuff
calsign
  • 341
  • 3
  • 12
  • The title is part of a View. But I don't understand it practically. To put the title in a View means, I have to disable it in the landscape-view. I guess via code and not via xml. But then how to add it on the right side? I thought the title spans over the complete main-screen. Sorry, but I am not THAT firm with the layout-ing. – LeO Sep 05 '12 at 15:39
  • @LeO: See my diagram. If this isn't what you want, that's fine. It's what I see in the picture in your question. – calsign Sep 05 '12 at 15:51
  • Generally speaking the idea looks fine. The screenshot is a fake one, that's the goal I wanna achieve. Currently it spans over the whole area cause it's the same from portrait. But thanks for the moment for the idea, I guesses now I need to fumble around ;-) – LeO Sep 05 '12 at 20:02
  • Sorry, but seems like I am still stuck. Although I like your idea, the question remains how to do it practically? I have my title.xml which defines the title and the components. I make a `setContentView(R.layout.main)` and then `getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,title.xml)`. But to make it like you suggest, does it mean, to hide the application Title Bar? And how to specify for ViewB that it should use title.xml? Resp. set it? – LeO Sep 06 '12 at 09:45
  • Thx for support, especially for the drawing which gave me good overview in which direction to progress – LeO Sep 07 '12 at 09:57
1

I suggest you set the Android Title bar to be hidden and add your own TextView as shorter TitleBar.
This way you have more possibilites desgining your layout.

Thommy
  • 5,070
  • 2
  • 28
  • 51
  • If I follow your advice, I am curious if I can reuse the specification of title.xml (==> How?) OR do I need to specify it once more? I mean the advantage to have it in the title.xml would be to have it in portrait and landscape with the same code and I don't have to worry about redefinition. – LeO Sep 06 '12 at 09:49
  • And one more question that just came into my mind is about the background-color. Cause currently Android is responsible, IFF I redesign it, than I have to take care - also for future changes. Is there currently an easy way to retieve them from the defaults? – LeO Sep 06 '12 at 10:03
  • You can always inflate an xml. Just look for the InflaterService on the Android Homepage. Also you can use the Background-Color from the current Android-System by using "android.R." – Thommy Sep 06 '12 at 11:28
  • see my posted answer. Thx your hints helped me a lot. – LeO Sep 07 '12 at 09:56
0

Based on the previous answer I found the solution with

_______________________________
|              |--------------|
|              || Title-View ||
|              |--------------|
|    View A    |    View B    |
|              |              |
|              |              |
|              |              |
-------------------------------

and a general Style which disables the app-title-header. Some side-effects are:

  • since the title-view-components are not persistent I need to reinitialize them as soon as the device is rotated (prior this was not necessary) [But this is a minor effort]
  • in the title-view I set android:background="@android:drawable/title_bar" which layouts the view the same style as a regular Android-title
  • I included hardcoded in the all layouts the Title-view with

        <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/title_2_lines" />
    

    which is also no big deal and works great.

Thx for support cause the two different ideas helped a lot to figure out a way how to make it properly :)

LeO
  • 4,238
  • 4
  • 48
  • 88