2012-01-14 108 views
2

我有一种情况,我需要创建一个左侧面板。我的经理说这应该与电视中使用的电视相同电影 Google TV设备上的应用程序,它最初只显示图标,并在右侧显示图标文字时显示其内容。创建Android左侧面板,就像在谷歌电视“电视和电影”应用程序中的一个

我想标签是像下面的图片(白色箱子是我的链接和红色ractangle是我左图)在:

Required Left Panel Structure

放大的图像可以被看作here

我对左面板的要求是:

  1. 它应该扩展到正确的s当它的任何一个链接被聚焦时,这个链接就会被放置。我的动画宽度不应该很难。但我怎么知道一个控件是左面板有/失去焦点
  2. 当在左面板中单击任何链接时,将单独的活动加载到右侧的FrameLayout中......我也使用解决方法。但我宁愿知道一些体面的好方法。
  3. 左侧面板的宽度应该减小,并且当用户通过按下右侧D-PAD按钮来聚焦加载的活动时应该隐藏图标的文本。

  4. 我必须可自由能使用左面板和在该容器的FrameLayout加载的子活动控制之间KEYBOARD导航。这是因为我的应用程序适用于Google TV,用户可以使用D-Pad进行导航。 这是我面临的主要问题......由于我无法从子控件到其父的邻居控制导航

要具有上述所有的点,我看着TabHost却苦于找不到让它看起来像我需要的那种方式。

我也看过themissingtabwidget,但它的垂直制表符填充了所有垂直可用空间,并且在那里放置对我来说是不可控的,我需要更多像左侧面板一样的结构,我可以在任何地方放置链接。所以这也失败了。

现在我决定自己创建一个。 我这样做的方式如下:

  1. main.xml中包含的FrameLayout在根持有
    • 的FrameLayout举办活动 - 我从左边,这样设置其利润率下一个左侧面板将适合该空间&何时将覆盖在它下面的框架,当我动画面板的大小
    • 相对eLayout用于放置左侧面板项目。

main.xml中如下:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<!-- 
    THIS First TabHost IS NOT USED AT ALL. 
    I JUST PUT IT HERE AS THE underlying TabActivity required it and was giving me error. 
    You can see its visibility is set to GONE. 

    You can just minimize it and forget it as its a silly Workaround. 
    and help me if you know of some better way 
--> 
<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="100dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="0" 
      android:orientation="vertical" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</TabHost> 

<!-- 
    Activities are loaded here in this frame. 
    Its margin from Left is set to 150dp to have space. 
    Its placed on the first place as the second RelativeLayout would be used as Left Panel. 
--> 
<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="150dp" 
    android:nextFocusLeft="@+id/leftpanel" 
    android:background="#CCAAAA" > 
</FrameLayout> 

<!-- 
    Left Panel holding links/buttons etc to load a separate activity in above FrameLayout 
--> 
<RelativeLayout 
    android:id="@+id/leftpanel" 
    android:layout_width="200dp"   
    android:layout_height="fill_parent" 
    android:background="#33FAFAFA" 
    android:focusable="True" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/btnArtists" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Artists" > 
    </Button> 

    <Button 
     android:id="@+id/btnAlbum" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/btnArtists" 
     android:text="Album" > 
    </Button> 

    <Button 
     android:id="@+id/btnLogin" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="True" 
     android:text="Login" > 
    </Button> 
</RelativeLayout> 

主选项卡活性如下:

public class TestActivity extends TabActivity { 
FrameLayout container; 
Intent artistsIntent; 
Intent albumsIntent; 

/** Called when the activity is first created. */ 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    container = (FrameLayout)findViewById(R.id.container); 
    artistsIntent = new Intent().setClass(this, ArtistsActivity.class); 
    albumsIntent = new Intent().setClass(this, AlbumsActivity.class); 

    Button btnArtist = (Button)findViewById(R.id.btnArtists);   
    btnArtist.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      container.removeAllViews(); 
      View view = getLocalActivityManager().startActivity("ArtistsActivity", 
        new Intent(getApplicationContext(), ArtistsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 
      container.addView(view);     
     } 
    }); 

    Button btnlbum = (Button)findViewById(R.id.btnAlbum); 
    btnlbum.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      container.removeAllViews(); 
      View view = getLocalActivityManager().startActivity("AlbumsActivity", 
        new Intent(getApplicationContext(), AlbumsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView(); 
      container.addView(view); 

     } 
    }); 
}  
} 

作为您可以看到主要的TestActivity是一个TabActivity,它提供了实现选项卡的功能。我从TabActivity扩展我的活动,因为根据我的知识,这是将活动添加到FrameLayout作为子视图的唯一方法。

这也迫使我有一个具有该特定名称的TabHost。所以我添加它并将其可见性设置为不见了以使其停止抱怨。 ...... 是我知道...这是一个愚蠢的替代方法 ..但我就不会在这里如果我知道一些适当的方式......所以帮助我,如果有一些更好的方式来做到这一点。

我目前的测试项目中的另一个问题是,当我在以的FrameLayout使用右箭头键加载的子活动焦点的按钮。我不能回用LEFT集中在左侧面板中的按钮键盘键...

HOW TO DO IT ????????????

我已经上传小样本项目here。请下载并查看它。同时在AndroidManifest.xml中将.TestActivity的主题设置为android:theme =“@ android:style/Theme.Holo”,以按照预期在全屏中查看应用。

你的帮助是极大的赞赏。

注意:我正在为Google TV创建此应用程序...导航主要依赖于D-Pad ...所以我必须确保使用Kayboard可以到达任何位置。

帮帮我吧。

回答

1

Android碎片对您的目的来说是完美的。看看documentation,这真的很清楚,并解释如何正确使用它。

相关问题