首页 \ 问答 \ 使用RecycleView时设置列的宽度(set width of columns when using RecycleView)

使用RecycleView时设置列的宽度(set width of columns when using RecycleView)

user.py

import kivy

kivy.require('1.9.0')  # replace with your current kivy version !
import sqlite3 as lite
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty,NumericProperty
from kivy.lang import Builder

from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.button import Button
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.popup import Popup
from kivy.core.window import Window



Window.size = (500, 500)

#con = lite.connect('test.db')
#con.text_factory = str
#cur = con.cursor()


class SelectableRecycleGridLayout(FocusBehavior, LayoutSelectionBehavior,
                                  RecycleGridLayout):
    ''' Adds selection and focus behaviour to the view. '''


class SelectableButton(RecycleDataViewBehavior, Button):
    ''' Add selection support to the Button '''
    index = None
    selected = BooleanProperty(False)
    selectable = BooleanProperty(True)

    def refresh_view_attrs(self, rv, index, data):
        ''' Catch and handle the view changes '''
        self.index = index
        return super(SelectableButton, self).refresh_view_attrs(rv, index, data)

    def on_touch_down(self, touch):
        ''' Add selection on touch down '''
        if super(SelectableButton, self).on_touch_down(touch):
            return True
        if self.collide_point(*touch.pos) and self.selectable:
            return self.parent.select_with_touch(self.index, touch)

    def apply_selection(self, rv, index, is_selected):
        ''' Respond to the selection of items in the view. '''
        self.selected = is_selected





class RV(BoxLayout):
    data_items = ListProperty([])

    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.get_users()

    def get_users(self):
        #cur.execute("SELECT * FROM `users` order by id asc")
        #rows = cur.fetchall()
        '''This result retrieve from database'''
        rows = [(1, 'Yash', 'Chopra'),(2, 'amit', 'Kumar')]

        for row in rows:
            for col in row:
                self.data_items.append(col)


class ListUser(App):
    title = "Users"

    def build(self):
        self.root = Builder.load_file('user.kv')
        return RV()



if __name__ == '__main__':
    ListUser().run()

user.kv

    #:kivy 1.10.0

<SelectableButton>:
    # Draw a background to indicate selection
    canvas.before:
        Color:
            rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
        Rectangle:
            pos: self.pos
            size: self.size

<RV>:
    BoxLayout:
        orientation: "vertical"

        GridLayout:
            size_hint: 1, None
            size_hint_y: None
            height: 25
            cols: 3

            Label:
                text: "ID"
            Label:
                text: "First Name"
            Label:
                text: "Last Name"

        BoxLayout:
            RecycleView:
                viewclass: 'SelectableButton'
                data: [{'text': str(x)} for x in root.data_items]
                SelectableRecycleGridLayout:
                    cols: 3
                    default_size: None, dp(26)
                    default_size_hint: 1, None
                    size_hint_y: None
                    height: self.minimum_height
                    orientation: 'vertical'
                    multiselect: True
                    touch_multiselect: True

有人能帮我吗?
1.如何根据显示打开全尺寸窗口。还应显示标题栏,最小化,交叉选项。
2.如何设置宽度ID = 20%和名字:40%和姓氏:40%。所有列都相等。


user.py

import kivy

kivy.require('1.9.0')  # replace with your current kivy version !
import sqlite3 as lite
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty, ListProperty, StringProperty, ObjectProperty,NumericProperty
from kivy.lang import Builder

from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.button import Button
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.popup import Popup
from kivy.core.window import Window



Window.size = (500, 500)

#con = lite.connect('test.db')
#con.text_factory = str
#cur = con.cursor()


class SelectableRecycleGridLayout(FocusBehavior, LayoutSelectionBehavior,
                                  RecycleGridLayout):
    ''' Adds selection and focus behaviour to the view. '''


class SelectableButton(RecycleDataViewBehavior, Button):
    ''' Add selection support to the Button '''
    index = None
    selected = BooleanProperty(False)
    selectable = BooleanProperty(True)

    def refresh_view_attrs(self, rv, index, data):
        ''' Catch and handle the view changes '''
        self.index = index
        return super(SelectableButton, self).refresh_view_attrs(rv, index, data)

    def on_touch_down(self, touch):
        ''' Add selection on touch down '''
        if super(SelectableButton, self).on_touch_down(touch):
            return True
        if self.collide_point(*touch.pos) and self.selectable:
            return self.parent.select_with_touch(self.index, touch)

    def apply_selection(self, rv, index, is_selected):
        ''' Respond to the selection of items in the view. '''
        self.selected = is_selected





class RV(BoxLayout):
    data_items = ListProperty([])

    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.get_users()

    def get_users(self):
        #cur.execute("SELECT * FROM `users` order by id asc")
        #rows = cur.fetchall()
        '''This result retrieve from database'''
        rows = [(1, 'Yash', 'Chopra'),(2, 'amit', 'Kumar')]

        for row in rows:
            for col in row:
                self.data_items.append(col)


class ListUser(App):
    title = "Users"

    def build(self):
        self.root = Builder.load_file('user.kv')
        return RV()



if __name__ == '__main__':
    ListUser().run()

user.kv

    #:kivy 1.10.0

<SelectableButton>:
    # Draw a background to indicate selection
    canvas.before:
        Color:
            rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
        Rectangle:
            pos: self.pos
            size: self.size

<RV>:
    BoxLayout:
        orientation: "vertical"

        GridLayout:
            size_hint: 1, None
            size_hint_y: None
            height: 25
            cols: 3

            Label:
                text: "ID"
            Label:
                text: "First Name"
            Label:
                text: "Last Name"

        BoxLayout:
            RecycleView:
                viewclass: 'SelectableButton'
                data: [{'text': str(x)} for x in root.data_items]
                SelectableRecycleGridLayout:
                    cols: 3
                    default_size: None, dp(26)
                    default_size_hint: 1, None
                    size_hint_y: None
                    height: self.minimum_height
                    orientation: 'vertical'
                    multiselect: True
                    touch_multiselect: True

Can someone help me?
1. how to open window in full size according to display.and still should show title bar,minimize,cross option.
2. How to set width ID = 20% and First name : 40% and Last Name : 40%.At this all columns are equal.


原文:https://stackoverflow.com/questions/47176777
更新时间:2024-03-17 21:03

最满意答案

很简单。

我建议不要将整个项目发送到视图。 它有很多数据。

@model IEnumerable<Item>

@foreach (var item in Model)
{
    <span>@item.Name</span>
}

请参阅我的回答,使用Glass Mapper将可编辑的sitecore字段从控制器渲染发送到视图。 它比整个项目小得多。

https://sitecore.stackexchange.com/questions/2795/best-practice-for-implementing-a-controller-rendering-using-glasscontroller/2803#2803

这里也是Sitecore MVC的绝佳资源。 Sitecore社区MVC示例项目。

https://github.com/Sitecore-Community/sample-sitecore-mvc


Simple as this.

I would recommend against sending the whole item to the view. Its a lot of data.

@model IEnumerable<Item>

@foreach (var item in Model)
{
    <span>@item.Name</span>
}

See my answer here for using Glass Mapper to send editable sitecore fields to a view from a controller rendering. Its much smaller than the entire item.

https://sitecore.stackexchange.com/questions/2795/best-practice-for-implementing-a-controller-rendering-using-glasscontroller/2803#2803

Also here is a great resource for Sitecore MVC. The Sitecore community MVC example project.

https://github.com/Sitecore-Community/sample-sitecore-mvc

相关问答

更多
  • 1.您可以通过在加载视图时拥有一组客户来执行此操作,当用户键入名称时,您可以使用您拥有的数组检查此值。 需要注意的是,你必须从控制器中获取php数组的js数组。 2.使用ajax。 简单而有活力。 1.You can do this by having a array of customers when you loading the view, when user types the name you can check this value with array you have. It is to b ...
  • 首先,问题来自于我没有认为与手边的问题有关的一条遗漏的陈述。 所以,对我感到羞耻。 在视图中,用复选框创建列表的代码段看起来像这样: @{ for (int i = 0; i < Model.BrandList.Count(); i++) { string columbia = "Columbia"; string choiceRewards = "Choice Rewards Preview"; if (!Model.Bran ...
  • 您应该创建一个ViewModel,其中包含您在视图中需要的所有信息。 public class MyViewModel { public List TheFirstTable {get;set;} public List TheSecondTable {get;set;} } 你可以像这样填充它 MyViewModel viewModel = new MyViewModel(); viewModel.TheFirstTable = //first table c ...
  • 我使用隐藏字段的形式帮助我做到这一点: - 我稍微改变了我的视图页面,如下所示: - for ($i=0; $i <$arraysize; $i++) { echo "

    ".($i+1).". ".$title[$i]." | ".$category[$i]." | ".$priority[$i]." | ".$date[$i]." | ".$post_status[$i]."

    "; echo form_open('/helpdesk/full_post'); echo ...
  • 我会研究attributes和appends 。 您可以通过调整模型来执行您想要的操作。 竞争
  • 是的,现在您可以从视图中访问数据,例如,在index.gsp中: Test${urls}
    ${page} 一般来说,grails默认返回函数中的最后一个值,因此如果要访问许多数据,可以这样做: class MyController { def flickrService def index = { def data = ... def data1 = ... ...
  • 相关文章

    更多
  • hibernate有两个一对多的Set时怎么写hbm
  • 7月最新发布11.2.0.1.2 Patch set update
  • RCFileInputFormat的使用方法
  • Ext的例子 中有关grid渲染数据的问题
  • div中table100%宽度的浏览器兼容性问题
  • ListView具有多种item布局——实现微信对话列
  • ListView具有多种item布局——实现微信对话列
  • maven设置本地仓库
  • 一个灰常简单的panel里设置HTML. 加了style后为什么会换行?
  • POI设置打印区域
  • 最新问答

    更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)