Android XML 布局问题

发布于 2024-11-25 14:22:01 字数 4080 浏览 1 评论 0原文

我想让我的第一个选项卡的布局如下所示:

在此处输入图像描述

我已经问了一个类似于这。我陷入了格式设置的困境: 这就是我的代码的样子:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"        
            android:layout_width="fill_parent"        
            android:layout_height="fill_parent"        
            android:padding="5dp">        
        <TabWidget
             android:id="@android:id/tabs"            
             android:layout_width="fill_parent"            
             android:layout_height="wrap_content" />        
        <FrameLayout            
            android:id="@android:id/tabcontent"            
            android:layout_width="fill_parent"            
            android:layout_height="fill_parent"            
            android:padding="5dp" /> 
            <RelativeLayout 
                android:orientation="vertical"                
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"    >            
                <ImageView
                    android:id="@+id/simpleMode"
                    android:layout_width="wrap_content"         
                    android:layout_height="wrap_content" 
                    android:padding = "5dip"
                    android:layout_alignParentLeft="true"           
                    android:src="@drawable/ic_tab_artists_grey" />  
                <TextView     
                    android:id="@+id/right_text"        
                    android:layout_width="fill_parent"        
                    android:layout_height="wrap_content"        
                    android:padding="5dip"        
                    android:layout_toRightOf="@+id/simpleMode"        
                    android:gravity="right"             
                    android:text="Description"        />                 
            </RelativeLayout>       
        </LinearLayout>
</TabHost>

我的项目运行但屏幕上完全没有显示任何内容?非常感谢帮助!

这是我的活动课: 包 com.joshi.remotedoc;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.Intent;
import android.content.res.Resources;

public class Detailed_ModeActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.patientmode);    
        Resources res = getResources(); 
        // Resource object to get Drawables    
        TabHost tabHost = getTabHost();  
        // The activity TabHost    
        TabHost.TabSpec spec;  
        // Reusable TabSpec for each tab
        Intent intent;  
        // Reusable Intent for each tab
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, SimpleMode.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("simpleMode").setIndicator("simpleMode",
                res.getDrawable(R.drawable.ic_tab_artists_white))
                .setContent(intent);    
        tabHost.addTab(spec);
        // Do the same for the other tabs
        intent = new Intent().setClass(this, DetailedMode.class);
        spec = tabHost.newTabSpec("2ndtab").setIndicator("MySecondTab",                          res.getDrawable(R.drawable.something))                      .setContent(intent);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("detailedMode").setIndicator("detailedMode",
                res.getDrawable(R.drawable.ic_tab_artists_grey))
                .setContent(intent);    
        tabHost.addTab(spec);
        tabHost.setCurrentTab(2);
}

    }

I want to make my layout for my first tab something like this:

enter image description here

I have already asked a question similar to this. I am getting stuck on the formatting:
This is what my code looks like:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout
            android:orientation="vertical"        
            android:layout_width="fill_parent"        
            android:layout_height="fill_parent"        
            android:padding="5dp">        
        <TabWidget
             android:id="@android:id/tabs"            
             android:layout_width="fill_parent"            
             android:layout_height="wrap_content" />        
        <FrameLayout            
            android:id="@android:id/tabcontent"            
            android:layout_width="fill_parent"            
            android:layout_height="fill_parent"            
            android:padding="5dp" /> 
            <RelativeLayout 
                android:orientation="vertical"                
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"    >            
                <ImageView
                    android:id="@+id/simpleMode"
                    android:layout_width="wrap_content"         
                    android:layout_height="wrap_content" 
                    android:padding = "5dip"
                    android:layout_alignParentLeft="true"           
                    android:src="@drawable/ic_tab_artists_grey" />  
                <TextView     
                    android:id="@+id/right_text"        
                    android:layout_width="fill_parent"        
                    android:layout_height="wrap_content"        
                    android:padding="5dip"        
                    android:layout_toRightOf="@+id/simpleMode"        
                    android:gravity="right"             
                    android:text="Description"        />                 
            </RelativeLayout>       
        </LinearLayout>
</TabHost>

My project runs but absolutely nothing shows up on the screen? Help is very much appreciated!!

Here is my activity class:
package com.joshi.remotedoc;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.Intent;
import android.content.res.Resources;

public class Detailed_ModeActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.patientmode);    
        Resources res = getResources(); 
        // Resource object to get Drawables    
        TabHost tabHost = getTabHost();  
        // The activity TabHost    
        TabHost.TabSpec spec;  
        // Reusable TabSpec for each tab
        Intent intent;  
        // Reusable Intent for each tab
        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, SimpleMode.class);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("simpleMode").setIndicator("simpleMode",
                res.getDrawable(R.drawable.ic_tab_artists_white))
                .setContent(intent);    
        tabHost.addTab(spec);
        // Do the same for the other tabs
        intent = new Intent().setClass(this, DetailedMode.class);
        spec = tabHost.newTabSpec("2ndtab").setIndicator("MySecondTab",                          res.getDrawable(R.drawable.something))                      .setContent(intent);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("detailedMode").setIndicator("detailedMode",
                res.getDrawable(R.drawable.ic_tab_artists_grey))
                .setContent(intent);    
        tabHost.addTab(spec);
        tabHost.setCurrentTab(2);
}

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平安喜乐 2024-12-02 14:22:01

您需要正确定义布局,然后需要在正在启动的活动中加载布局。

http://developer.android.com/guide/topics/ui/declaring -layout.html

首先创建 XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="vertical" >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello, I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello, I am a Button" />
</LinearLayout>

然后您需要创建 Java 来在 oncreate 方法中加载 XML:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
}

You need to properly define your layout, then you need to load your layout in the activity you are starting.

http://developer.android.com/guide/topics/ui/declaring-layout.html

First you create your XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="vertical" >
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Hello, I am a TextView" />
    <Button android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello, I am a Button" />
</LinearLayout>

Then you need to create the Java to load your XML in the oncreate method:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文