【问题标题】:Textview should be placed higher on the screenTextview 应该放在屏幕上更高的位置
【发布时间】:2016-09-06 07:01:45
【问题描述】:

我在我的文本视图中添加了一个链接,但由于某种原因,整个文本视图被放置在我的屏幕中心,而不是顶部。我添加了显示错误位置的图像。

有谁知道这是为什么,我该如何解决?

这是我的主要活动代码:

package com.example.rodekruis;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Html;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class FoldersActivity extends Activity implements View.OnClickListener{


     TextView HyperLink;
     Spanned Text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_folders);

        findViewById(R.id.button11).setOnClickListener(this);
        findViewById(R.id.button12).setOnClickListener(this);
        findViewById(R.id.button13).setOnClickListener(this);
        findViewById(R.id.button14).setOnClickListener(this);
        findViewById(R.id.imageButton1).setOnClickListener(this);

        TextView textView =(TextView)findViewById(R.id.textView);
        textView.setClickable(true);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        String text = getResources().getString(R.string.title_activity_folders);
        text += "<a href='https://www.rkz.nl/overzicht'> Klik daarvoor op deze link</a>";
        textView.setText(Html.fromHtml(text));


    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {


            case R.id.button11:
                Uri uri = Uri.parse("https://www.facebook.com/RKZ.BrandwondencentrumBeverwijk");
                intent = new Intent(Intent.ACTION_VIEW, uri);
                break;
            case R.id.button12:
                Uri uri1 = Uri.parse("https://www.youtube.com/user/rodekruisziekenhuis/featured");
                intent = new Intent(Intent.ACTION_VIEW, uri1);
                break;
            case R.id.button13:
                Uri uri2 = Uri.parse("https://twitter.com/rodekruiszh?lang=nl");
                intent = new Intent(Intent.ACTION_VIEW, uri2);
                break;
            case R.id.button14:
                Uri uri3 = Uri.parse("https://www.linkedin.com/company/rode-kruis-ziekenhuis");
                intent = new Intent(Intent.ACTION_VIEW, uri3);
                break;
            case R.id.imageButton1:
                intent = new Intent(FoldersActivity.this, InfoActivity.class);
                break;
        }
        startActivity(intent);
    }

}

这是我的 xml 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.rodekruis.Folders" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="1dp"
        android:src="@drawable/rkz_logo" />

    <ImageView
        android:id="@+id/imageButton1"
        android:layout_width="40dp"
        android:layout_height="50dp"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:layout_gravity="right" 
        android:src="@drawable/informatiebutton" />
    </FrameLayout>

    <ScrollView
         android:id="@+id/scrollview"
         android:layout_width="fill_parent"
         android:layout_height="364dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="244dp"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:layout_gravity="center"
        android:text="@string/title_activity_folders"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/black" />




</ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="15dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button11"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Facebook" />

        <Button
            android:id="@+id/button12"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Youtube" />

        <Button
            android:id="@+id/button13"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="Twitter" />

        <Button
            android:id="@+id/button14"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="LinkedIn" />

    </LinearLayout>
</LinearLayout>

这是显示 textview 位置错误的图像:

【问题讨论】:

  • textview 重力=开始
  • 从文本视图中删除:android:layout_gravity="center"
  • android:layout_gravity="center" 删除它并设置您查看 Textview 的位置。
  • Text View 包含此android:layout_gravity="center",因此请删除该属性。否则将其值更改为android:layout_gravity="top"

标签: java android eclipse


【解决方案1】:

试试这个 xml 代码。而不是 android:layout_gravity="center" 使用 android:layout_gravity="center_horizontal"

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.rodekruis.Folders" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="1dp"
        android:src="@drawable/rkz_logo" />

    <ImageView
        android:id="@+id/imageButton1"
        android:layout_width="40dp"
        android:layout_height="50dp"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="10dp"
        android:layout_gravity="right" 
        android:src="@drawable/informatiebutton" />
    </FrameLayout>

    <ScrollView
         android:id="@+id/scrollview"
         android:layout_width="fill_parent"
         android:layout_height="364dp" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="244dp"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:layout_gravity="center_horizontal"
        android:text="@string/title_activity_folders"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="@color/black" />
</ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="15dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button11"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Facebook" />

        <Button
            android:id="@+id/button12"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:text="Youtube" />

        <Button
            android:id="@+id/button13"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="Twitter" />

        <Button
            android:id="@+id/button14"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignLeft="@+id/button5"
            android:layout_below="@+id/button8"
            android:layout_marginLeft="5dp"
            android:layout_weight="1"
            android:text="LinkedIn" />

    </LinearLayout>
</LinearLayout>

【讨论】:

  • 谢谢伙计,很明显,但我似乎找不到。干杯
【解决方案2】:

尝试删除最后一个 ImageView 的 marginBottom 和 TextView 的 marginTop 和 layout_gravity。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    相关资源
    最近更新 更多